How do I format a double to currency rounded to the nearest dollar?

后端 未结 6 1070
春和景丽
春和景丽 2020-12-05 03:58

Right now I have

double numba = 5212.6312
String.Format(\"{0:C}\", Convert.ToInt32(numba) )

This will give me

$5,213.00
         


        
6条回答
  •  伪装坚强ぢ
    2020-12-05 04:29

    I think the right way to achieve your goal is with this:

    Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalDigits = 0;
    

    and only then you should do the Format call:

    String.Format("{0:C0}", numba) 
    

提交回复
热议问题