Link to home
Start Free TrialLog in
Avatar of theartha
thearthaFlag for United States of America

asked on

NumberFormat in c#

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

Avatar of kaufmed
kaufmed
Flag of United States of America image

Provided value is of a numeric type, try:

value.ToString("C")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of theartha
theartha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theartha

ASKER

This solution works for me.
Avatar of dj_alik
dj_alik

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