Round function

  • Thread starter Thread starter martin
  • Start date Start date
M

martin

Hi,

I see that there is not round function in vb.net as the vb one has been
take out.

my question is what is the best function to round a number variable to a
given number of decimal places.

eg

dim intTes as double = 100.345673

what is the best way to round this to 2 decimal places so the value now
reads

100.34

the way I have been doing it is to multiply by 100, cast to an integer and
the ues a double to the value when that integer is divided by 100.
not very elegant so i guess there must be a better way.

thanks for any advice.

cheers

martin.
 
Hi Martin,

You can simply convert it to string with the required formatting
intTes.ToString("0.00");

Anu

----- martin wrote: -----

Hi,

I see that there is not round function in vb.net as the vb one has been
take out.

my question is what is the best function to round a number variable to a
given number of decimal places.

eg

dim intTes as double = 100.345673

what is the best way to round this to 2 decimal places so the value now
reads

100.34

the way I have been doing it is to multiply by 100, cast to an integer and
the ues a double to the value when that integer is divided by 100.
not very elegant so i guess there must be a better way.

thanks for any advice.

cheers

martin.
 
Back
Top