StevieB
StevieB

Reputation: 6543

ASP.NET Convert money datatype to displayable value on screen

Just pulled from database a value from DB with datatype and appearing on my screen as

9.8600

Whats best way to get this to get to

€9.86

Upvotes: 0

Views: 443

Answers (1)

JonH
JonH

Reputation: 33163

Pass it to ToString with a c you can optionally add an integer after the letter c for the precision. If I wanted 2 digits after the decimal "c2"

valueFromDB.ToString("c")

For C#:

decimal value = 123.456m;
Console.WriteLine("Your account balance is {0:C2}.", value);
// Displays "Your account balance is $123.46."

For VB:

Dim value As Decimal = 123.456d
Console.WriteLine("Your account balance is {0:C2}.", value)
' Displays "Your account balance is $123.46."

If in doubt, MSDN : http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

enter image description here

Upvotes: 2

Related Questions