CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Floating Point Rounding Routine

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
diegonet



Joined: 13 Sep 2005
Posts: 4

View user's profile Send private message

Floating Point Rounding Routine
PostPosted: Tue Sep 13, 2005 11:02 pm     Reply with quote

Hi to everybody!
I'm looking for a routine to rounding to x number of decimal digits a floating point number.
In several C languaje implementations there's at least one form of implementation (e.g. round (var, x)).

The thing that I need to do is like this:

4.146898 after rounding to 2 decimal digits => 4.15

Somebody could help me?
Best Regards and thank's
Ttelmah
Guest







PostPosted: Wed Sep 14, 2005 3:23 am     Reply with quote

#define round(x,n) (floor(x*(10.0^n)+0.49)/(10.0^n)))

Best Wishes
Bart



Joined: 12 Jul 2005
Posts: 49

View user's profile Send private message

PostPosted: Wed Sep 14, 2005 2:48 pm     Reply with quote

Ttelmah wrote:
#define round(x,n) (floor(x*(10.0^n)+0.49)/(10.0^n)))

Best Wishes


And where do I get the floor ?[/b]
_________________
I like Skype (www.skype.com), my username is BplotM
Ttelmah
Guest







PostPosted: Wed Sep 14, 2005 2:58 pm     Reply with quote

Floor is a standard library function (as is ceil), included in the compiler. You need to include 'math.h' to use it.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group