Rounding off

How would i round off to 2 decimal places?
my sprite.timeScale is not working, and im assuming this is the reason

roundedNumber = math.floor(sourceNumber * 100 + 0.5) / 100

or

roundedNumber = math.round(sourceNumber * 100)/100

edited because I forgot there was a .round() function. The multiply by 100 then divide by 100 shifts your decimal place by 2 spots temporarily since .round, .floor etc make intergers, then the divide by 100 puts it back to 2 decimal places.

it doesnt help having it if its not documented anywhere....
Thank you anyway, it didnt help though, the timeScale function itself is very broken

Hello wiredknight,

The timeScale value is already rounded at the 2 decimal place internally when calculating animation speed, even though the property value may not reveal it. Meaning, if you set timeScale to 0.009, then internally it will be calculated as 0.01 but in Lua it will remain as 0.009. This was the intent so that developers can easily increment the timeScale in Lua in a nice linear fashion without Corona unexpectedly rounding it up/down.

So, what problems are you having with the sprite's timeScale property?
Based on my testing, it seems to be working perfectly as documented.

Hi Joshua

I solved my problem another way, however i really could not get the timescale thing to work, and i was not the only user, i seen others complain.

Maybe its nitty gritty things that were not specified, like for example it HAS to be before you play, or after.... etc

But what i ended up have happening is that it made no effect, or it would work up until 2.0, and down as far as need be

Hello wiredknight,

You can indeed change the timeScale property while it is playing. Trust me, it works. Also, if you're trying to set timeScale to a very high value, then you're going to need to bump up the frame rate of your app to 60 FPS or else it will be capped at the default 30 FPS.

So far, you haven't told me what the problem is. What isn't working for you? And can you provide some example code?

Currently, there are no bugs reported for the timeScale property. So we don't know what complaints you are referring to. If you think there is a bug then please report it via the "Report a Bug" link at the top of this page. Thanks!

views:1686 update:2011/10/11 15:24:38
corona forums © 2003-2011