Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

VC++ question

Thread Tools
 
Search this Thread
 
Old 30 November 2006, 01:05 PM
  #1  
TopBanana
Scooby Regular
Thread Starter
 
TopBanana's Avatar
 
Join Date: Jan 2001
Posts: 9,781
Likes: 0
Received 0 Likes on 0 Posts
Default VC++ question

Anyone know how to round a float to a long in MS Visual C++? C++ isn't really my scene...
Old 30 November 2006, 01:11 PM
  #2  
ChefDude
Scooby Regular
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

cast it using long c=(long)flt_var;
Old 30 November 2006, 01:23 PM
  #3  
TopBanana
Scooby Regular
Thread Starter
 
TopBanana's Avatar
 
Join Date: Jan 2001
Posts: 9,781
Likes: 0
Received 0 Likes on 0 Posts
Default

Thanks for the reply but you can't do that with float. e.g. 120 as a float comes out as 119 because it's really 119.99999999999998.
Old 30 November 2006, 01:58 PM
  #4  
DanPhillips
Scooby Regular
 
DanPhillips's Avatar
 
Join Date: May 2000
Posts: 225
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by ChefDude
cast it using long c=(long)flt_var;
long c = (long) ceil(flt_var);

Should do it nicely

Cheers

Dan
Old 30 November 2006, 02:00 PM
  #5  
ChefDude
Scooby Regular
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

roundf?
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
slimwiltaz
General Technical
20
09 October 2015 07:40 PM
IanG1983
Wheels, Tyres & Brakes
2
06 October 2015 03:08 PM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
the shreksta
Other Marques
26
01 October 2015 02:30 PM



Quick Reply: VC++ question



All times are GMT +1. The time now is 09:50 PM.