Firetron’s CountDecimals

2 129 Views 2 Comments 2 months ago
  • Returns the number of decimal places in a number.

    HaasScript Code
    --  ============================================================================
    --    Firetron's CountDecimals
    --
    --    Returns the number of decimal places in a number.
    --
    --    Discord:  @FiretronP75
    --    BTC Tips: 14WLDZsrhshcP6qvBarKW8ABACv3iUXEro
    --    ETH Tips: 0xfaaac99fbf11f8f4abc4b3bf079cb2c7a43b5f87
    --  ============================================================================
    
    --  ========================================================
    --    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')
    • #1151
      Firetron
      Basic
      Up
      1
      Down

      Thank you for your help on this pshai

      • This reply was modified 1 month, 3 weeks ago by Firetron. Reason: Made hyperlink pretty
    • #1154
      pshai
      Admin
      Up
      1
      Down

      No, thank you for making it awesome 😉

Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free