The 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

+4
source share
3 answers

This 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 

For more information on formatting numbers, see these pages.

+2
source

You need to format the data when it is output:

 myMoney.ToString("0.00"); 
+1
source

Are you sure you are not 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 in the MSDN Custom Numeric Formatting Strings section to determine the format string that will be passed to the ToString method for decimal, double, single structures or the static Format method in the String class .

+1
source

Source: https://habr.com/ru/post/1302545/


All Articles