在VB.Net中将数字从DB转换为小数

时间:2012-07-30 21:40:20

标签: vb.net number-formatting

在表格中保存的金额没有小数点。

1 = 0.01, 10 = 0.10, 100 = 1.00, 1000 = 10.00.

我想在vb.net中显示它是如何将其转换为常规十进制格式的?

1 个答案:

答案 0 :(得分:0)

如果值作为字符串存储在数据库中,则将其解析为数字:

Dim n as Integer = Int32.Parse(theString)

然后只需将数字转换为浮点数,然后除以100:

Dim d as Double = Convert.ToDouble(n) / 100.0

由于/运算符始终在VB中进行浮点除法,因此可以将其转换为隐式转换:

Dim d as Dobule = n / 100.0