By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,502 Members | 1,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,502 IT Pros & Developers. It's quick & easy.

Round a float...

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

"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

P: n/a
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

P: n/a

"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.