Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Take away decimals.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
commandos




PostPosted: Thu May 01, 2008 11:22 pm   Post subject: Take away decimals.

I need to divide two numbers that are always going equal some fraction (smaller number divided by bigger number), then multiply it by 100 and keep it as an integer. Pretty much I need to make a percentage of somthing without any decimals and have it as an integer. Any idea of how I might go about doing this?
Sponsor
Sponsor
Sponsor
sponsor
commandos




PostPosted: Thu May 01, 2008 11:26 pm   Post subject: RE:Take away decimals.

Pfft I feel like an idiot... Literally seconds after I posted this i found the round function which does everything i want it to... Thanks though
gitoxa




PostPosted: Fri May 02, 2008 4:25 pm   Post subject: RE:Take away decimals.

Just to point out, there's three functions that do can do this for you.

round
- returns the closest whole number
round(2.4) = 2
round(4.8) = 5

ceil
- returns the closest whole number coming after the original number
ceil(2.4) = 3
ceil(4.8) = 5

floor
- returns the closest whole number coming before the original number
floor(2.4) = 2
floor(4.8) = 4


lol mistakes. Thanks Cavetroll
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: