开发者

Formatting decimal numbers

I am using VB.NET 2010 Premium and SQL Server 2008 Express.

I have an integer, 1562, which I multiply by 0.1.

In my SQL database I have a field named, Y_751_207, as a Decimal(18,0). In my program I have a textbox named, txtY_751_207.

objDataRow.item("Y_751_207") = CType(txtY_751_207.text, Double) * 0.1

As I stepped through the code I verified that my result was ok. 156.2, but when I display my answers into 开发者_StackOverflowmy ListView it displays as 156. I need for it to display as 156.2.

Simulary

I have an Integer, 39993824, which I multiply by 10 ^ -6.

In my SQL database I have a field named, Y_751_594, as a Decimal(18,0). In my program I have a textbox named, txtY_751_594.

objDataRow.item("Y_751_594") = CType(txtY_751_594.text, Double) * 10 ^ -6.

As I stepped through the code I verified that my result was ok. 39.993824, but when I display my answers into my ListView it displays as 40. I need for it to display as 39.993824.

On paper I have verified my results to be correct. I have tried to get it right but I am having no luck.


The problem is the data type of your columns: Decimal(18,0)

The 18 means, "How many total digits".

The 0 Means, "How many digits to the right of the decimal point"

Since your scale is 0, your values will be rounded to the nearest whole number. You should decide on the precision and scale you need for your columns and set them appropriately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜