I'm scripiting a dice game which involves dividing the number on the 12 sided dice by the number on the 4 sided dice for example 2 / 4 = 0.5. I'm trying to make it round down to the nearest whole number to the results that involve decimal places. If you can please help it will be much appreciated.
Offline
Rounding down to the nearest whole number is called the Floor Function, and is abbreviated as [x]. (Coincidentally, rounding up to the nearest whole number is called the Ceiling function). Here are the stacks you need:
when gf clicked set [x v] to [3.14] say (round ((x)-(0.5)))//Floor function = 3 say (round ((x)+(0.5)))//Ceiling function = 4 say (round (x))//Normal round function = 3
Last edited by Hardmath123 (2012-04-02 06:02:00)
Offline
Sorry, I'm not that great with scratch.. Why is it 3.14? All i need to use is the floor function. Also the -0.5 etc wouldnt work because if i rolled a 7 on the 12 sided dice and a 3 on the 4 sided dice it would get 2.333??... I want it so that it rounds to 2 (an interger).
Sorry you probably explained it above, I just can't understand it ;ss.
Offline
Ok, simply put, rather than say (round (2.33333)) you would use (round ((2.33333)-(0.5))). In math-y terms, just subtract 0.5 from the number, then ound it to get the floor of that number. Get it? I admit it, I could have been clearer in the first post.
Last edited by Hardmath123 (2012-04-02 06:58:02)
Offline
Be careful, through. Althrough 3 rounded up equals 3, the +0.5 method will return 4.
This method works best:
when I receive [round up v] if <(round (number)) = (number)> set [rounded number v] to (number) else set [rounded number v] to (round ((number) + (0.5))) endBeware: This error also occurs if you round down a negative number. To fix this, use this code:
when I receive [round down v] if <(round (number)) = (number)> set [rounded number v] to (number) else set [rounded number v] to (round ((number) - (0.5))) endAlso, this simpler equation will have no errors too:
((number) - ((number) mod (1)))
Last edited by rdococ (2012-04-03 12:32:28)
Offline