1

I need only up to two decimal points.

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

It gives me values like per1=76.34393939202

But if I use : Dim Per1, Per2, Per3, Per4, per5 As ULong It gives me 76

I want that it to gives me values like 76.34 but how i can do it? Please help me.

a3.14_Infinity
  • 5,653
  • 7
  • 42
  • 66
sangeen
  • 304
  • 2
  • 3
  • 14

2 Answers2

4

If you convert a Double to ULong it will remove all decimal places. If the problem is when you print them to screen, then you can simply use a string formatter:

Format(Per1, "0.00")

Documentation can be found here http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.format.aspx

If you want to round the numbers you can use

Math.Round(Per1, 2)

Round is documented here http://msdn.microsoft.com/en-us/library/75ks3aby.aspx

Hope this helps

david
  • 804
  • 7
  • 21
0

in c# it looks like this

 string.Format("{0:0.00}", (double)Convert.ToInt32(tv) * 100 / Convert.ToInt32(v1))
mbeso
  • 244
  • 1
  • 8