NumberFormat in c#

theartha
theartha used Ask the Experts™
on
Hi There,

I am converting a piece of Java code to C#, I am having problems with NumberFormat. How to write the below java code in c#

Please advice.

Thanks.
NumberFormat fmt;
      String fmtValue;
      StringBuffer buffer;
      char charArray[];
      int i;
            
      fmt = NumberFormat.getCurrencyInstance();
      fmtValue = fmt.format(value);
      buffer = new StringBuffer();
      charArray = fmtValue.toCharArray();
         for(i = 0; i < charArray.length; i++){
               if(Character.isDigit(charArray[i]) == true){
                  buffer.append(charArray[i]);
                  }
            }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Provided value is of a numeric type, try:

value.ToString("C")

Open in new window

Commented:
I used String.Format("{0:0,0.0}", value);

this works.

Thanks.

Author

Commented:
This solution works for me.
Top Expert 2011

Commented:
if value is double or float:
value.ToString("0,0.0")

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial