472,342 Members | 1,588 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 34808

"Terje Barman" <terje_nospam_@_nospam_barman-hanssen.no> wrote in message
news:7N********************@telenor.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(float) -> int, thus I can do as follows:

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

Terje
"Oliver Wong" <ow***@castortech.com> skrev i melding
news:Wp2ff.200172\$ir4.172405@edtnps90...

"Terje Barman" <terje_nospam_@_nospam_barman-hanssen.no> wrote in message
news:7N********************@telenor.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********************@telenor.com...
Thanks Oliver!

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

float f = 1.234;
f *= 100;
f = (float)Math.round(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.