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

Round float to the nearest integer

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







Round float to the nearest integer
PostPosted: Fri Apr 25, 2003 2:54 am     Reply with quote

Dear all,

If a=ceil(1.9)
Then, a=2

If a=floor(1.9)
Then, a=1

May I know how to round a float number to the nearest integer?
Ex. : 1.9-------2
1.2-------1
1.3-------1

Thanks.


Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 13988
R.J.Hamlett
Guest







Re: Round float to the nearest integer
PostPosted: Fri Apr 25, 2003 3:08 am     Reply with quote

:=Dear all,
:=
:=If a=ceil(1.9)
:=Then, a=2
:=
:=If a=floor(1.9)
:=Then, a=1
:=
:=May I know how to round a float number to the nearest integer?
:=Ex. : 1.9-------2
:= 1.2-------1
:= 1.3-------1
:=
:=Thanks.
:=
:=
:=Einly
The normal method, in C, is:
a=floor(n+0.49999);

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13989
Einly
Guest







Thanks:)
PostPosted: Sun Apr 27, 2003 1:00 am     Reply with quote

Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 14017
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