Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 8:56 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Rounding a number...
PostPosted: Fri Jan 09, 2009 3:47 pm 
Offline

Joined: Sun Nov 09, 2008 7:01 pm
Posts: 21
Hi,

If I have a floating point number like 1.6, how do I round it up to the nearest whole number?

I tried making an integer variable equal to the floating point variable but it only takes the whole number (in this case 1), without actually rounding it up to 2.

Thanks!

B. Blair


Top
 Profile  
 
 Post subject: Re: Rounding a number...
PostPosted: Fri Jan 09, 2009 3:49 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Converting a float to an integer always rounds down (by design). To round normally, add 0.5
Code:
dim flt as float
dim int as integer

flt := 1.6
int := flt + 0.5

'Int will contain 2

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject: Re: Rounding a number...
PostPosted: Fri Jan 09, 2009 3:52 pm 
Offline

Joined: Sun Nov 09, 2008 7:01 pm
Posts: 21
Perfect! And thanks for such a rapid respsonse!

B.Blair


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group