playMaker

Author Topic: Convert Int/Float to String - now with Format Option  (Read 13342 times)

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Convert Int/Float to String - now with Format Option
« on: May 21, 2011, 07:30:22 AM »
In many circumstances it helps a lot to get a string formatted in a specific way straight during the conversion stage from an int of float, instead of going through a routine to format the string after the fact. C# has some nice built-in format strings just for that, which weren't exposed in Playmaker - so far :)

A couple good examples of use:

-Leading zeroes on an int-converted variable. Suppose you have values like 20, 140 and want to see them shown as 0020, 0140, etc. To do that you'd use Format = "0000" or "D4"

- Format in percentage notation a float number, for instance, convert 0.2 to 20% in a statistics display. For that you'd use format = "P2".

For more information on the available options, read here:
http://www.blackwasp.co.uk/CSharpNumericToString.aspx

To install simply overwrite the original actions in Assets/Playmaker/Actions. If it's an existing project don't worry, these actions are compatible with any existing data, if the 'format' field is set to null it performs the original, no-format behavior. Hope you find it of use, enjoy!
--
Breno "MaDDoX" Azevedo
@brenoazevedo

edufurla

  • Junior Playmaker
  • **
  • Posts: 56
Re: Convert Int/Float to String - now with Format Option
« Reply #1 on: October 07, 2013, 04:06:40 PM »
Nice addition.
Thanks for sharing.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Convert Int/Float to String - now with Format Option
« Reply #2 on: January 23, 2015, 02:11:03 PM »
To get 98% (no decimals) then it's:
#%