PDA

View Full Version : How to display number divided with comma in edittext


feilang
04-30-2008, 07:57 AM
HI,may be this is easy for you,but i don't know how to.Will you anyone help me,my honor for you! The code:
rollout test "test" width:162 height:81
(
local num=12345678
editText edt1 "" pos:[26,28] width:108 height:22
on test open do
( edt1.text=num as string )
)
createdialog test
so we get 12345678,but i want to get like this:12,345,678 then i can read the number more easier.May that come true im mxs?

thatoneguy
04-30-2008, 08:41 AM
fn CommaNumbers numberstring =
(
wholenumbers = filterstring numberstring "."
decimals = wholenumbers[2]
numberstring = wholenumbers[1]
for i = (numberstring.count - 3) to 1 by -3 do
(
numberstring = replace numberstring i 1 (numberstring[i]+",")
)
if decimals != undefined do
(
append numberstring ("."+decimals)
)
return numberstring
)
CommaNumbers "12345678.51231544"

feilang
04-30-2008, 09:00 AM
oops! Great job thatoneguy,my appreciation for you.now it is easy to me too,LOL...

thatoneguy
04-30-2008, 09:01 AM
fn CommaNumbers numberstring divstring:"," =
(
DecimalOffset = findstring numberstring "."
if DecimalOffset != undefined then (DecimalOffset -= 1) else (DecimalOffset = numberstring.count)
for i = (DecimalOffset - 3) to 1 by -3 do
(
numberstring = replace numberstring i 1 (numberstring[i]+divstring)
)
return numberstring
)
CommaNumbers "1234553.456464654122248"
Slightly different approach with the ability to localize that much easier in case your nation uses . instead of comma or what have you.

feilang
04-30-2008, 09:15 AM
you are so circumspect,the second one is more easier for me really.Whatever,thanks a lot!

ZeBoxx2
05-02-2008, 03:01 PM
don't forget about negative numbers ;)


CommaNumbers "-321234553.456464654122248"
"-,321,234,553.456464654122248"


Easily fixed:

fn CommaNumbers numberstring divstring:"," = (
local start = if (numberString[1] == "-") then ( 2 ) else ( 1 )
DecimalOffset = findstring numberstring "."
if DecimalOffset != undefined then (DecimalOffset -= 1) else (DecimalOffset = numberstring.count)
for i = (DecimalOffset - 3) to start by -3 do
(
numberstring = replace numberstring i 1 (numberstring[i]+divstring)
)
return numberstring
)

CommaNumbers "-321234553.456464654122248"
"-321,234,553.456464654122248"

DaveWortley
05-02-2008, 03:07 PM
Does FormattedPrint() not work for this?

ZeBoxx2
05-02-2008, 05:44 PM
Does FormattedPrint() not work for this?
nay
(this text to pass 10-letter minimum requirement)

feilang
05-04-2008, 03:04 AM
[QUOTE=ZeBoxx2]don't forget about negative numbers ;)

I really forgotten about it ,thank you:)

sunboy69
05-05-2008, 09:00 AM
Hi Lwang, long time no see , are you ok?
The question was sure solved that such many superiors help you!
Felicitate to U!

CGTalk Moderation
05-05-2008, 09:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.