Rounding up & Down to 2 decimal places

garcon

Well-known member
I have a double with about 8 number after the decimal place. How do you display just 2 after the decimal place?

Thanks,
G.

TPM

Well-known member
Use a Decimal and round it. Or you could use a string, remove.

TPM

garcon

Well-known member
Thanks man - I'm using:

doubleVar = Math.Round(doubleVar, 2)

uthrauthra

New member
Rounding upto 2 decimals

i am using round of method for 2 decimal places it works fine for

round(1.646,2) ---> 1.65

But, if i use

round(1.645,2) --> 1.64

JuggaloBrotha

VB.NET Forum Moderator
Staff member
uthrauthra said:
i am using round of method for 2 decimal places it works fine for

round(1.646,2) ---> 1.65

But, if i use

round(1.645,2) --> 1.64

vb uses statistical rounding that that is correct

ie: 1.5 will round to 2, and 2.5 will also round to 2
3.5 will round to 4, and 4.5 will also round to 4

uthrauthra

New member
some other way to round upto two decimals

how can this be solved. is there any other way to solve this it is very critical.please provide a solution.

Thank u

regards,
utr

MNeb

Member
As with anything in programming, if the provided functions do not give the desired output, you will have to code it yourself.

You will need to find if the 3rd decimal place is 0 - 4 or 5-9 and round the second decimal place accordingly. Then decide if you want to consider 1.1449 to be 1.14 or 1.15.

Replies
6
Views
153
Replies
0
Views
434
Replies
1
Views
68
Resolved .NET Native
Replies
1
Views
277
Replies
4
Views
1K