Firetron's FormatRoundedPercent
stableDescription
Formats a number to be rounded and have the percent symbol.
Custom Command Dependencies:
None
Test code:
if not Load('done', false) then
local closes = ClosePrices()
local close1 = ArrayGet(closes, 1)
local close2 = ArrayGet(closes, 2)
local change = PercentageChange(close1, close2)
Log(' ')
Log(change)
Log('Chnage:')
Log(' ')
local formatted = CC_FormatRoundedPercent(change)
Log(formatted)
Log('Formatted Default:')
Log(' ')
local formatted2 = CC_FormatRoundedPercent(change, 4, ' @')
Log(formatted2)
Log('Formatted Another Way:')
Log(' ')
Save('done', true)
end
HaasScript
-- ============================================================================
-- Firetron's FormatRoundedPercent
--
-- Formats a number to be rounded and have the percent symbol.
--
-- Custom Command Dependencies:
-- None
--
-- Discord: @FiretronP75
-- ============================================================================
-- ========================================================
-- Variables
-- ========================================================
-- ------------------------------------
-- Definition
-- ------------------------------------
local dDefault
local dDescription
local dName
local dOutput
local dRequired
local dSuggestions
local dType
-- ------------------------------------
-- Parameter
-- ------------------------------------
local pDigits
local pInput
local pSymbol
-- ========================================================
-- Command Definition
-- ========================================================
dName = 'FormatRoundedPercent'
dDescription = 'Formats a number to be rounded and have the percent symbol.'
DefineCommand(dName, dDescription)
-- ========================================================
-- Parameter Definitions
-- ========================================================
dType = NumberType
dName = 'input'
dDescription = 'The number to format.'
dRequired = true
dDefault = 0
dSuggestions = ''
pInput = DefineParameter(dType, dName, dDescription, dRequired, dDefault, dSuggestions)
dType = NumberType
dName = 'digits'
dDescription = 'The digits to round to.'
dRequired = false
dDefault = 2
dSuggestions = ''
pDigits = DefineParameter(dType, dName, dDescription, dRequired, dDefault, dSuggestions)
dType = StringType
dName = 'symbol'
dDescription = 'The symbol to append.'
dRequired = false
dDefault = ' %'
dSuggestions = ''
pSymbol = DefineParameter(dType, dName, dDescription, dRequired, dDefault, dSuggestions)
-- ========================================================
-- Output Definition
-- ========================================================
dType = StringType
dOutput = Round(pInput, pDigits)..pSymbol
dDescription = 'The formatted value.'
dSuggestions = 'Log'
DefineOutput(dType, dOutput, dDescription, dSuggestions)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!