Display text: Percentages?

mhedgesmhedges Raised on VCSMember Posts: 634

Hello

I get stumped by the silliest of things. I have a value (real) which is the division of two real variables. Can I format the Display Text to have the value displayed as a percentage, such as "12.34%"? Or do I have to multiply by 100 and concatenate a "%" in there? LOL.

Thanks, regards.

Comments

  • BBEnkBBEnk Member Posts: 1,764

    you could do display test like so game.value.."%"

  • mhedgesmhedges Raised on VCS Member Posts: 634

    YEs, @BBEnk, that would be the concatenate option. But how can I format a real variable to two decimal places? Thanks!

  • pHghostpHghost London, UKMember Posts: 2,342

    @mhedges said:
    But how can I format a real variable to two decimal places? Thanks!

    Using the Precision Function:

    prec(your.number,2)

    You're welcome!

  • mhedgesmhedges Raised on VCS Member Posts: 634

    Thanks, @pHghost ! So close, yet still a bit to go. I was trying out padInt and padReal when I saw your response.

    Thanks to both, regards.

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2014

    @pHghost said:
    Using the Precision Function: prec(your.number,2)

    I'm pretty sure the precision function is (like the modulus '%' function) no longer recommended by GameSalad, I guess its days are numbered and will eventually get dropped as the code base is evolved . . . . the recommendation to ensure future compatibility is to use 'round' and 'roundTo' instead . . . so basically roundTo(your.number,2).

    Also I've heard it said that the precision function needs to convert the numbers to text before doing its magic and then convert the results back to a number, which is meant to be a slower less efficient method than staying in the world of numbers (which 'round' does).

  • pHghostpHghost London, UKMember Posts: 2,342

    @Socks -- good to know! Had no idea these functions might get dropped by GS soon.

Sign In or Register to comment.