vb.net currency display has four zeros instead of two

when i get the money field from sql server to vb.net code, i always get 1.0000 instead of 1.00. how do i convert this to 1.00 in vb.net?

TD = New HtmlTableCell

If Not SqlDR("Price") Is DBNull.Value Then
    TD.InnerHtml = SqlDR("Price")
Else
    TD.InnerHtml = "0.00"
End If

SQLDR is my sql data reader

Answers


That is because SQL Server stores the MONEY field with 4 decimal places. To see it with 2, use the String.Format method.

String.Format("{0:c}", 10) ''result: $10.00

String.Format("{0:N2}", 10) ''result: 10.00

See these pages for more ways to format your numbers


You need to format the data when you output it:

myMoney.ToString("0.00");

Are you sure you aren't confusing the display of the value with the actual value?

1.0000 and 1.00 are the same value.

If you want to display only a certain number of places when converting a value to a string, you should look at the Custom Numeric Format Strings section in the MSDN documentation to figure out the format string to pass to the ToString method on the Decimal, Double, Single structures, or the static Format method on the String class.


Need Your Help

TFS: How to Completely Ignore files by name-pattern (or glob?)

visual-studio-2012 tfs tfvc

We have migrated a project from Mercurial to TFS 2013. The project uses ASP.NET Web API and TypeScript and there are many, many automatically generated files.

XML parsing error in php

php xml domdocument

When I use the below code and parse the xml locally it works fine but when upload the same script at the server it shows error. the code is