Firetron's CountDecimals

stable
By Firetron in Miscellaneous Published August 2020 👁 1,767 views 💬 2 comments

Description

Returns the number of decimal places in a number.
HaasScript
--  ============================================================================
--    Firetron's CountDecimals
--
--    Returns the number of decimal places in a number.
--
--    Discord:  @FiretronP75
--  ============================================================================

--  ========================================================
--    Definition
--  ========================================================

DefineCommand('CountDecimals', 'Returns the number of decimal places in a number.')

--  ========================================================
--    Parameters
--  ========================================================

local value = DefineParameter(NumberType, 'value', 'something like 1.234', true, 1.234, 'MinimumTradeAmount, ParseTradePrice')

--  ========================================================
--    Output
--  ========================================================

local valueString = Parse(value, StringType)
local splitString = StringSplit(valueString, '.')
local output

if #splitString == 1 then

  output = 0

else

  local decimalString = splitString[2]

  output = #decimalString

end

DefineOutput(NumberType, output, 'the number of decimal places in a number')

2 Comments

Sign in to leave a comment.

F
Firetron almost 6 years ago

Thank you for your help on this pshai

P
pshai almost 6 years ago

No, thank you for making it awesome ;)