472,342 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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.

Similar topics

4
by: Jason Tesser | last post by:
I am using Rekall which uses Python as it's scripting language and I have a question about Python. I am developing a POS system and am working on ...
5
by: Peter Scheurer | last post by:
Hi, we found some strange behavior when operating with floats and round(). The following simplified statement reproduces the problem. select ...
8
by: David Corby | last post by:
Hi everybody, I've got a problem. I'm trying to round a double to a particular number of significant digits, in this case 5, but I can't figure...
6
by: Nobody | last post by:
How does one round a float? ie... 4.4 returns 4, while 4.5 returns 5. I see the floor and ceiling functions, but that floor would take 4.4 and...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the...
2
by: Steve | last post by:
I have float value, let say 123.456789. How can I round it to two decimal digits after decimal point? For example: 123.456789 -> 123.45 It...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of...
3
by: Nader | last post by:
Hello, I have a list of tuple with strin elements. These elements are number, but they are save as string. Now I will change the string to number...
2
by: Nimbus | last post by:
In my case, if the float value is 74.716, it has to rounding into 74.72. But is that value is 74.715, it should be 74.71.. can anyone tel me what...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.