Hi guys,
I’m looking for a help with this. I want my “newText” to only show 7 characters because it is a result of a mathematical equation and when the result is a periodic number the newText leaves my content area preventing its reading on the screen of the phone.
Ex: 70.833333333
I want my text to show only 70.833
Here is the code.
-- calc button function local function calcButtonTouch( event ) if ( event.phase == "began" ) then audio.play( flick ) elseif ( event.phase == "ended" ) then local sum = tonumber( field\_1.text ) + tonumber( field\_2.text ) local mult = tonumber( field\_1.text ) \* tonumber( field\_2.text ) local step\_1 = sum / mult local step\_2 = step\_1 \* tonumber( field\_3.text ) \* tonumber( field\_4.text ) \* 6.1 local finalStep = step\_2 \* tonumber( field\_5.text ) result.text = finalStep end end
I try this
... elseif ( event.phase == "ended" ) then local sum = tonumber( field\_1.text ) + tonumber( field\_2.text ) local mult = tonumber( field\_1.text ) \* tonumber( field\_2.text ) local step\_1 = sum / mult local step\_2 = step\_1 \* tonumber( field\_3.text ) \* tonumber( field\_4.text ) \* 6.1 local finalStep = step\_2 \* tonumber( field\_5.text ) myNum = 7 -- max characters if string.len(result.text) \> myNum then result.text = result.text:sub( 1, 7 ) end result.text = finalStep end ...
Nothing happens, continue giving me the long result.
Thanks in advance