473,993 Members | 5,700 Online

# Round a float...

Hi!

I have sumarized float values and I'd like to round the sum to a certain
precision. Say I have 1.234 and want it rounded to 1.23. Which method can I
use?

Terje
Nov 22 '05 #1
3 34931

"Terje Barman" <terje_nospam_@ _nospam_barman-hanssen.no> wrote in message
news:7N******** ************@te lenor.com...
Hi!

I have sumarized float values and I'd like to round the sum to a certain
precision. Say I have 1.234 and want it rounded to 1.23. Which method can
I use?

Math.round();

- Oliver
Nov 22 '05 #2
Thanks Oliver!

I found that Math.Round(floa t) -> int, thus I can do as follows:

float f = 1.234;
f *= 100;
f = (float)Math.rou nd(f)/100;
.... and now f==1.23

Terje
"Oliver Wong" <ow***@castorte ch.com> skrev i melding
news:Wp2ff.2001 72\$ir4.172405@e dtnps90...

"Terje Barman" <terje_nospam_@ _nospam_barman-hanssen.no> wrote in message
news:7N******** ************@te lenor.com...
Hi!

I have sumarized float values and I'd like to round the sum to a certain
precision. Say I have 1.234 and want it rounded to 1.23. Which method can
I use?

Math.round();

- Oliver

Nov 22 '05 #3

"Terje Barman" <terje_nospam_@ _nospam_barman-hanssen.no> wrote in message
news:H9******** ************@te lenor.com...
Thanks Oliver!

I found that Math.Round(floa t) -> int, thus I can do as follows:

float f = 1.234;
f *= 100;
f = (float)Math.rou nd(f)/100;
... and now f==1.23

Terje

Yes, exactly. =) Good luck with your project.

- Oliver
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.