How to format a number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gracepaul
    New Member
    • Jul 2008
    • 28

    #1

    How to format a number

    hi all,

    How to format a number in the following format

    if the number is 1123456789.20 then i want the result as follows
    1,12,34,56,789. 20

    please reply as early as possible

    thanks in advance

    grace
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Are you using the comma to separate three digits or two digits?
    Code:
    doubleValue.ToString("#,###.00");

    Comment

    • cloud255
      Recognized Expert Contributor
      • Jun 2008
      • 427

      #3
      So do you want to put any given number into that format?

      I take it that the number is split based on value.

      So you should treat the number as a string. work from right to left. search for a "." if the string contains one, that should be treated as the starting point, if not start from the last character.

      then ignore the first 3 characters (that is when working from the right). place a "," after the first 3 characters, then a "," after every second character. one for loop and some standard .NET string manipulation commands should do the trick.

      Comment

      Working...