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

后端 未结 6 1067
春和景丽
春和景丽 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:30

    This should do the job:

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

    The number after the C specifies the number of decimal places to include.

    I suspect you really want to be using the decimal type for storing such numbers however.

提交回复
热议问题