Format 1234 into 1,234.00
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Format 1234 into 1,234.00
I've had a look at the Format function in the dictionary
but very hard to follow as no practical examples and their outcomes.
Looks almost like assembler.
I'm used to something like this:
xString = format ("z,zz0.00", 1234)
resulting in: 1,234.00
Anyone have a routine or two like this to help get me started?
Still looking ...
Also, if there is a function in the DataGrid that will assist with this formatting
that would be super cool.
but very hard to follow as no practical examples and their outcomes.
Looks almost like assembler.
I'm used to something like this:
xString = format ("z,zz0.00", 1234)
resulting in: 1,234.00
Anyone have a routine or two like this to help get me started?
Still looking ...
Also, if there is a function in the DataGrid that will assist with this formatting
that would be super cool.
Last edited by BarrySumpter on Wed Aug 10, 2011 11:43 pm, edited 2 times in total.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Format 1234 into 1,234.00
Hi Barry,
have a look at this:
http://runtime-revolution.278305.n4.nab ... 27469.html
the topic just came up on the use-Livecode-list.
Kind regards
Bernd
have a look at this:
http://runtime-revolution.278305.n4.nab ... 27469.html
the topic just came up on the use-Livecode-list.
Kind regards
Bernd
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format 1234 into 1,234.00
How fortuatous!
I started with the Scriptors Scrapbook and have been moding ever since the original post
Don't use this yet as I'm starting to work on the pDecPlaces and cleaning up to look and sound better:
You can see where I'm going here.
pCurrency can be something like "AU $" or "$AU "or just "$" , or empty etc.
pSeperator(,) and pDecimal(.) can be any character. If it ain't there then don't use it etc.
This code looks terrible with no LiveCode text color on the forum.
Is there a way I can get the code to display with the same colors as LiveCode text editor (no mods).
I started with the Scriptors Scrapbook and have been moding ever since the original post
Don't use this yet as I'm starting to work on the pDecPlaces and cleaning up to look and sound better:
Code: Select all
function fmtNum pNum, pCurrency, pSeparator, pDecimal, pDecPlaces
-- Syntax: fmtNum pNum [,pCurrency[,pSeparator[,pDecimal]]]
if pNum is not a number then
return "ERR: Not a number" -- return exist this routine
end if
if char 1 of pNum = "-" then
put "-" into prefix
put char 2 to -1 of pNum into pNum
end if
-- is Decimal = . then use decimal
if pDecimal="" then
-- put "" into pDecimal
set the numberFormat to "0"
else
-- otherwise don't use decimal
-- put "." into pDecimal
set the numberFormat to "0.00"
end if
-- force format onto number parameter
add 0 to pNum
if pDecPlaces is not empty then
if pDecPlaces is a number then
put round(pnum,pDecPlaces) into pnum
end if
end if
set the itemDelimiter to "."
-- Integer.Decimal
put item 1 of pNum into pInteger
put item 2 of pNum into holdDecimal
-- if the seperator not empty then use it otherwise don't
if pSeparator is not empty then
repeat with x = length(pInteger)-3 to 3 step -3
put pSeparator before char x+1 of pInteger
end repeat
end if
return (pCurrency && prefix & pInteger & pDecimal & holdDecimal)
end fmtNum
pCurrency can be something like "AU $" or "$AU "or just "$" , or empty etc.
pSeperator(,) and pDecimal(.) can be any character. If it ain't there then don't use it etc.
This code looks terrible with no LiveCode text color on the forum.
Is there a way I can get the code to display with the same colors as LiveCode text editor (no mods).
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Format 1234 into 1,234.00
Barry,
But you can also use -> format(xxxxx) in LiveCode! Check the dictionary!
Maybe that will do what you need?
Best
Klaus
No.BarrySumpter wrote:Is there a way I can get the code to display with the same colors as LiveCode text editor (no mods).
But you can also use -> format(xxxxx) in LiveCode! Check the dictionary!
Maybe that will do what you need?
Best
Klaus
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format 1234 into 1,234.00
Just stumbled on this LiveCode article:
39268-How-Do-I-Create-a-Formatting-Pattern-for-a-Column- (using Data Grid Helper)
http://lessons.runrev.com/s/lessons/m/4 ... -a-Column-
Seems I forgot that the Data Grid Helper was included in my OmegaBundle purchase.
Still giggling like a little girl when I realize just how great the OmegaBundle is.
39268-How-Do-I-Create-a-Formatting-Pattern-for-a-Column- (using Data Grid Helper)
http://lessons.runrev.com/s/lessons/m/4 ... -a-Column-
Seems I forgot that the Data Grid Helper was included in my OmegaBundle purchase.
Still giggling like a little girl when I realize just how great the OmegaBundle is.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Format 1234 into 1,234.00
Use the FieldFormatter extension to LiveCode properties. It is designed to do this automatically, along with many other display formatting options...
Link: http://www.FlexibleLearning.com/fieldformatter
Link: http://www.FlexibleLearning.com/fieldformatter
The Flexible Learning Company
• ChartMaker: www.FlexibleLearning.com/chartmaker
• ControlManager: www.FlexibleLearning.com/controlmanager
• The Scripter's Scrapbook: www.FlexibleLearning.com/ssbk
• DatePicker: www.FlexibleLearning.com/datepicker
• ChartMaker: www.FlexibleLearning.com/chartmaker
• ControlManager: www.FlexibleLearning.com/controlmanager
• The Scripter's Scrapbook: www.FlexibleLearning.com/ssbk
• DatePicker: www.FlexibleLearning.com/datepicker