Rounding of floats in c

Status
Not open for further replies.

ravix

Right off the assembly line
we all know that c rounds off floats while using them. can anybody tell me about the rule it follows.:confused:
 

JGuru

Wise Old Owl
Oops , I moved to Java long time back. I forgot C Language. I need to refer a good
C book!!
 

casanova

The Frozen Nova
[quote="deathvirus_me]Hmmm ... wasn't there a function like Abs or something ???[/quote]
Abs gives us the absolute value
eg
abs (-12)=12
abs(12.24)=12.00

The rounding of depends on the precision. Have never peeped into all this stuff. But floats have precision upto 6 decimals. And if you need to print say floats in 2 decimals, u can use %.2f as format specifier
 

Ishan

In the zone
I know this in C++..inclue the math.h
cout.precision(2);
cout<<1.2345;
OUTPUT
1.23

Clear?
 

bukaida

In the zone
You can use the floor and ceil function also to control the round off to next higher or lower digit.
 
Status
Not open for further replies.
Top Bottom