469,330 Members | 1,246 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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 34690

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jason Tesser | last post: by
8 posts views Thread by David Corby | last post: by
6 posts views Thread by Nobody | last post: by
6 posts views Thread by ng_mr | last post: by
2 posts views Thread by Steve | last post: by
116 posts views Thread by Dilip | last post: by
3 posts views Thread by Nader | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.