Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Razor view engine - how do I format a decimal value to have commas and two decimal places?

As the title suggests - I have a value in my viewmodel that is decimal. I have no control over that. I'd like to display it as currency using the Razor View Engine.

[email protected]("{0:0.00}", 1005.3422)

gets me part way there with:

$1005.34

but how can I get the commas in there?

Thanks

like image 271
BKahuna Avatar asked Aug 17 '11 02:08

BKahuna


People also ask

How do I format a string to two decimal places?

String strDouble = String. format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.

How can I add two decimal values in VB net?

I.e.: Label lblTellBMI will display Your BMI is: and then append the value from a Single type variable (sngBMI) as 2 decimal points, simply by using the Math. Round method. The Math. Round method rounds a value to the nearest integer or to the specified number of fractional digits.


1 Answers

Can you use {0:c} instead? This is just standard string formatting in .NET and the "c" is for currency. There are lots of standard numeric string formats. And, of course, custom formatting, too.

like image 160
Sumo Avatar answered Sep 21 '22 17:09

Sumo