Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format number as money

Tags:

string

c#

format

How do I format a number to look like this: 9,000 my database field is in money data type, when I pull it up I see it like this: 9000.0000 that don't look right to me (I would like it to look like a real money format)

like image 653
Alex Avatar asked May 04 '09 16:05

Alex


People also ask

What is the format for money?

United States (U.S.) currency is formatted with a decimal point (.) as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation.

How do you make a number into a currency in numbers?

In the Format sidebar, click the Cell tab, then click the Data Format pop-up menu and choose Currency. Do any of the following: Set the number of decimal places: In the Decimals field, type the number of decimal places you want to display. Numbers rounds the display value instead of truncating the display value.


2 Answers

While you could call string.format, I think it's easier to just call ToString on it.

decimal money = 9000m;
string formattedMoney = money.ToString("C");
like image 174
Powerlord Avatar answered Oct 09 '22 14:10

Powerlord


decimal money = 1000;
Response.Write(string.Format("{0:C}", money));

The above is an example in C#.

like image 30
Jon Avatar answered Oct 09 '22 13:10

Jon