LagAbuse.com
Unofficial Section => Programming => Topic started by: OtNePx on January 25, 2014, 08:22
-
Hello,
I am trying to make calculator with visual basic 6.0 for own purposes.
I already made it but i need round numbers after comma (.)
Example:
11.41 / 100 * 1.1394 = 0.13000554
I need only 2 digits after comma it should look 0.13
Any ideas how to make it?
-
Don't know in visual basic, but thing you are looking for is rounding numbers, lets say the result is:
0.148349, it will round it to 0.15
There is command for that.
-
You want : 0.1365454 to become 0,13 or 0,14
In any ase I can help you
-
http://msdn.microsoft.com/de-de/library/system.math.round.aspx
-
However, this link was the first hit when searching for visual+basic+6+round
As you can see, you can round a number now simple on 2 decimal numbers by using
/* foo = number to round, bar = decimal numbers */
foo = round( foo, bar);
Advanced:
/* small trick to round always up */
foo = round( foo, (bar+1));
/* same goes to always round down */
foo = round( foo, (bar-1));
Regards,
G-C
Ps: Wtf, why I can't edit my own post and this approval sucks.
If you fear spamming on the forum, you can simply go with an anti-spam-bot, for smf there a lot out on the web. I'm not a human.
-
Small fix:
/* small trick to round always up */
foo = round( foo, (bar+0.5));
/* same goes to always round down */
foo = round( foo, (bar-0.5));
Regards,
G-C