Rounding up & Down to 2 decimal places

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
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
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Use a Decimal and round it. Or you could use a string, remove.

TPM
 

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
Thanks man - I'm using:

doubleVar = Math.Round(doubleVar, 2)
 

uthrauthra

New member
Joined
Dec 31, 2004
Messages
4
Programming Experience
1-3
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

which is not correct could you please help on this
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
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

which is not correct could you please help on this
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
Joined
Dec 31, 2004
Messages
4
Programming Experience
1-3
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
Joined
Feb 22, 2005
Messages
21
Programming Experience
1-3
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.
 
Top Bottom