(vb.net) rounding to 2 decimal places

痴心易碎 提交于 2020-05-23 11:32:22

问题


I am creating a program for a project that will help me learn visual basic. But when I work out how much a certain material is worth with dimensions. It come out with more than two decimal places. I know how to use math.floor function but it doesn't round to 2 decimal places.

Does anyone know what function I should use to round to two decimal places?


回答1:


The Decimal.Round method will do the trick for you. You can specify the number of decimal places.




回答2:


You can use;

Math.Round([DECIMAL], 2)

If you want to round up you can use;

MidpointRounding.AwayFromZero

As an additional parameter to make;

Math.Round([DECIMAL], 2, MidpointRounding.AwayFromZero)

Hope it helps!



来源:https://stackoverflow.com/questions/40740838/vb-net-rounding-to-2-decimal-places

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!