Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Questions about text field and numbers — Gideros Forum

Questions about text field and numbers

KarrizKarriz Member
edited August 2013 in General questions
Hi, I've been wondering how can I limit the length of a number, so that instead of for example 7,458635 I'd get 7,5. This is probably basic lua stuff, but I don't know what to search for.

Also, is it possible to use the text field like the print() function, so that you can add multiple values and text strings?

Like this: print("Distance from target:", distancevalue, "meters")

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited August 2013 Accepted Answer
    1) no internal function but you can create one, like
    function math.round(num, idp)
      local mult = 10^(idp or 0)
      return math.floor(num * mult + 0.5) / mult
    end
     
    --and use it as
    print(math.round(25.9995, 2)) --results in 25.99
    2) string concatenation in lua is through two dots ..
    So you can do it like:
    TextField.new(nil, "Distance from target:"..distancevalue.."meters")
    ;)

    Likes: Karriz

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks, that helps a lot!
  • john26john26 Maintainer
    For formatted strings, you can use the string.format function which is part of the Lua standard library. This allows formatting using C-like syntax eg %12.3f

    See

    http://www.lua.org/pil/20.html
Sign In or Register to comment.