TreeHuginDruid
RIP
- Joined
- Sep 12, 2004
- RedCents
- 60¢
If anyone can figure out a simpler way to do this, I welcome the input.
Taking an integer value, and displaying it as a string value to show comma placement for thousands.
Turn DebugComma on (1) to see the step by step logic behind it when running.
Comma.mac
Taking an integer value, and displaying it as a string value to show comma placement for thousands.
Turn DebugComma on (1) to see the step by step logic behind it when running.
Comma.mac
Rich (BB code):
#turbo
|--------------------------------------------------------------------------------
|SUB: Main
|--------------------------------------------------------------------------------
Sub Main
|------------------------------------
| Required declarations.
|------------------------------------
/declare ValTotal int outer 1987123574
/declare ValTotalStr string outer
|------------------------------------
/call ValTotComma ${ValTotal}
/echo Final ValTotalStr=(${ValTotalStr})
/return
|--------------------------------------------------------------------------------
|--------------------------------------------------------------------------------
|SUB: ValTotComma(string ValTotalStrTmp)
|--------------------------------------------------------------------------------
Sub ValTotComma(string ValTotalStrTmp)
/declare i int local
/declare DebugComma int local 0
/if (${DebugComma}) /echo ValTotalLen=(${ValTotalLen}) ValTotalStrTmp=(${ValTotalStrTmp})
/if (${Int[${ValTotalStrTmp.Length}]}>3) {
/for i 1 to 4
/declare ValTotalStrP${i} string local
/if (${DebugComma}) /echo ValTotalStrTmp=(${ValTotalStrTmp}) ++
/if (${Int[${ValTotalStrTmp.Length}]}>=3) {
/varset ValTotalStrP${i} ${ValTotalStrTmp.Right[3]}
/if (${DebugComma}) /echo ValTotalStrP${i}=(${ValTotalStrP${i}}) -
/varset ValTotalStrTmp ${ValTotalStrTmp.Left[-3]}
/if (${DebugComma}) /echo ValTotalStrTmp.Length=(${ValTotalStrTmp.Length})
/if (${i}>1) {
/varset ValTotalStr ${ValTotalStrP${i}},${ValTotalStr}
} else {
/varset ValTotalStr ${ValTotalStrP${i}}${ValTotalStr}
}
/if (${DebugComma}) /echo ValTotalStr=(${ValTotalStr})
} else /if (${ValTotalStrTmp.Length}) {
/varset ValTotalStrP${i} ${ValTotalStrTmp.Right[3]}
/if (${DebugComma}) /echo ValTotalStrP${i}=(${ValTotalStrP${i}}) --
/varset ValTotalStr ${ValTotalStrP${i}},${ValTotalStr}
/varset ValTotalStrTmp
/if (${DebugComma}) /echo ValTotalStr=(${ValTotalStr})
}
/next i
} else {
/varset ValTotalStr ${ValTotalStrTmp}
}
/return
|--------------------------------------------------------------------------------
Last edited: