currency formatting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajitk
    New Member
    • Feb 2008
    • 77

    currency formatting

    Dear All,

    I am making a project using ASP.Net and C#.

    I have a text box where i enter the amount. What i want is that when the user goes to the next field, i want the amount to the formatted in the following way:

    For example, if the entered amount is 100000; i want it to be formatted as
    Rs. 1,00,000.00

    This Rs. is for Indian Rupees. This can be US Dollors or Euro also.

    Request your help please.

    Thanks
    Sajit
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I would think you could use string.format for that.
    Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to the String.Format method, see Get started with the String.Format method for a quick overview.


    If you are just trying to format as currency then a simple .ToString("c") will do the trick.

    Comment

    • faelnefal
      New Member
      • Nov 2008
      • 16

      #3
      try this

      int sample = 106070;
      Console.WriteLi ne(String.Forma t("{0:0,000,000 }",sample));

      Comment

      • sajitk
        New Member
        • Feb 2008
        • 77

        #4
        Dear faelnefal

        How will i show the value in the "sample" variable in a text box.

        Sajit

        Comment

        • faelnefal
          New Member
          • Nov 2008
          • 16

          #5
          in windows form control there are things called "properties "
          one of which is Text
          you put
          textBox1.Text = string.Format(" {0:c}",sample);

          Comment

          • sajitk
            New Member
            • Feb 2008
            • 77

            #6
            Dear faelnefal,

            thanks for the earlier mail

            Now suppose, if my sample has a value 12345, this format will display as 0,12,345.

            What i need to tackle this. What i want is that a function that will tackle all of this.


            Sjait

            Comment

            • sajitk
              New Member
              • Feb 2008
              • 77

              #7
              Dear faelnefal,

              When i use this function, a $ sign is preceeded everytime, is there a way i can change / remove this.

              textBox1.Text = string.Format(" {0:c}",sample);

              Sajit

              Comment

              Working...