Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 30-06-2006, 08:40 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Apr 2006
Posts: 4
Thumbs up Rounding of floats in c


we all know that c rounds off floats while using them. can anybody tell me about the rule it follows.
ravix is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 30-06-2006, 09:27 PM   #2 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Rounding of floats in c

Oops , I moved to Java long time back. I forgot C Language. I need to refer a good
C book!!
JGuru is offline  
Old 30-06-2006, 09:38 PM   #3 (permalink)
Wise Old Owl
 
deathvirus_me's Avatar
 
Join Date: May 2005
Location: Kolkata, India
Posts: 1,838
Default Re: Rounding of floats in c

Hmmm ... wasn't there a function like Abs or something ???
deathvirus_me is offline  
Old 30-06-2006, 11:26 PM   #4 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: Rounding of floats in c

Quote:
Originally Posted by "deathvirus_me
Hmmm ... wasn't there a function like Abs or something ???
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
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Old 01-07-2006, 08:43 PM   #5 (permalink)
In The Zone
 
Ishan's Avatar
 
Join Date: Jun 2005
Location: Bharuch,Gujarat,India
Posts: 366
Default Re: Rounding of floats in c

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

Clear?
__________________
When was the last time when you did something for the first time?
So many words for the broken heart.....

for world wars. ishangajera.blogspot.com
Ishan is offline  
Old 02-07-2006, 09:39 PM   #6 (permalink)
In The Zone
 
bukaida's Avatar
 
Join Date: Jul 2005
Location: KOLKATA
Posts: 267
Default Re: Rounding of floats in c

You can use the floor and ceil function also to control the round off to next higher or lower digit.
__________________
Desktop: P-IV 2.4GHz, 512MB DDR, 865GBF Mother Board,
G-Force 5200FX, 17" Samsung flat, WinXp with SP2,
Kaspersky Internet Security 2009.
Laptop:LENOVO 3000 C100 D7 lappy with 2GB DDR2.
bukaida is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clinton
- by ico
- by Charan
- by gohan89

Advertisement




All times are GMT +5.5. The time now is 11:06 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2