Notifications
Clear all

[Closed] How to display number divided with comma in edittext

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?

9 Replies
 

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"

oops! Great job thatoneguy,my appreciation for you.now it is easy to me too,LOL…

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.

you are so circumspect,the second one is more easier for me really.Whatever,thanks a lot!

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"

Does FormattedPrint() not work for this?

1 Reply
(@zeboxx2)
Joined: 11 months ago

Posts: 0

nay
(this text to pass 10-letter minimum requirement)

[QUOTE=ZeBoxx2]don’t forget about negative numbers

I really forgotten about it ,thank you:)

Hi Lwang, long time no see , are you ok?
The question was sure solved that such many superiors help you!
Felicitate to U!