forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rounding Decimals

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
soulphalanx



Joined: 22 Aug 2005
Posts: 35

PostPosted: Tue Aug 23, 2005 4:18 am    Post subject: Rounding Decimals Reply with quote

Can anyone tell me how to round down or round up a decimal number?
Back to top
View user's profile Send private message
Benihana



Joined: 31 Jul 2005
Posts: 12

PostPosted: Tue Aug 23, 2005 4:29 am    Post subject: Reply with quote

Programming in Lua
rounding functions (floor, ceil)

Wikipedia entry for floor and ceil
floor: for a real number x, floor(x) is the largest integer less than or equal to x.
ceil: for a real number x, ceiling(x) is the smallest integer no less than x.
Back to top
View user's profile Send private message
soulphalanx



Joined: 22 Aug 2005
Posts: 35

PostPosted: Tue Aug 23, 2005 4:50 am    Post subject: Reply with quote

luaplayer doesnt recognize floor(X) and ceiling(X)
Back to top
View user's profile Send private message
Benihana



Joined: 31 Jul 2005
Posts: 12

PostPosted: Tue Aug 23, 2005 4:59 am    Post subject: Reply with quote

That's because you didn't follow the link and look at the way it was used... it is part of the math library, therefore implentation is as follows:

local x = math.ceil(2.3)
print(x) --> 3
Back to top
View user's profile Send private message
Nils



Joined: 03 Aug 2005
Posts: 16

PostPosted: Thu Aug 25, 2005 3:42 am    Post subject: Reply with quote

try that.

Code:
function math.round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num  * mult + 0.5) / mult
end


x = 8.13
math.round(x) = 8
y = 8.52
math.round(y) = 9
_________________
Puzzle Bobble - The arcade port!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 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