![](/img/trans.png)
[英]How can I test if a user input is a decimal with no more than 2 digits after the decimal place?
[英]how i can reduce the digits after the decimal point?
我只需要最多两个小数点。
Dim v1,v2,v3,v4,v5,tv,rp1,rp2,rp3,rp4,rp5 As Double
Dim Per1,Per2,Per3,Per4,per5 As Double
Per1 = v1 / tv * 100
Per2 = v2 / tv * 100
Per3 = v3 / tv * 100
Per4 = v4 / tv * 100
per5 = v5 / tv * 100
它给我的值如per1 = 76.34393939202
但如果我使用:Dim Per1,Per2,Per3,Per4,per5 As ULong它给了我76
我希望它能给我76.34这样的价值,但我怎么做呢? 请帮我。
如果您将Double转换为ULong,它将删除所有小数位。 如果问题是当你将它们打印到屏幕时,那么你可以简单地使用字符串格式化器:
Format(Per1, "0.00")
文档可以在这里找到http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.format.aspx
如果你想要舍入你可以使用的数字
Math.Round(Per1, 2)
Round记录在这里http://msdn.microsoft.com/en-us/library/75ks3aby.aspx
希望这可以帮助
在c#中它看起来像这样
string.Format("{0:0.00}", (double)Convert.ToInt32(tv) * 100 / Convert.ToInt32(v1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.