REVO2700 ÿ accountancyFormat() P{function accountancyFormat pNumber,pRounded,pCurrency,pSeparator,pDecimal --// Neatly formats a number, whether positive or negative for uk accountancy purposes. Returns a hyphen for empty or zero. --// --// pNumber the number being evaluated --// pRounded true or empty returns a rounded number, false leaves pence to two decimal places --// pCurrency inserts a string before the result --// pSeparator empty returns a comma, specify an alternative here --// pDecimal empty returns a period, specify an alternative here local tOpenBracket,tCloseBracket,tTheDecimals -- is the value empty? if so, we'll return a hyphen if pNumber is empty then return "- " -- is this negative? if so, we'll return with brackets if char 1 of pNumber = "-" then delete char 1 of pNumber put "(" into tOpenBracket put ")" into tCloseBracket else put space into tCloseBracket end if if pSeparator="" then put "," into pSeparator if pCurrency="" then put empty into pCurrency if pRounded = "false" then if pDecimal="" then put "." into pDecimal set the numberFormat to "0.00" add 0 to pNumber else put round(pNumber) into pNumber end if set the itemDel to "." put item 2 of pNumber into tTheDecimals put item 1 of pNumber into pNumber repeat with i = length(pNumber)-3 to 3 step -3 put pSeparator before char i+1 of pNumber end repeat if pNumber = 0 and pDecimal = 0 then return "- " return (pCurrency && tOpenBracket & pNumber & pDecimal & tTheDecimals & tCloseBracket) end accountancyFormat ÿÿÿÿÿÿ € } mç ó accountancyFormat() ÿÿÿÿ U Lucida Grande U Monaco W Lucida Grande W Lucida Grande W Lucida Grande U Lucida Grande U Courier U Lucida Grande W Monaco W Lucida Grande cREVGeometryCache stackID 1023 cREVGeneral scripteditorvscroll 0breakpointconditions scripteditorselection 73breakpoints breakpointstates stackfileversion 2.7 ê @ € ç ö cREVGeometryCacheIDs 1242565789797 10091242564885084 10041242566098106 10161242564943920 10051242566098107 10171242566338966 10221242565979552 10131242566338967 10231242566080076 10141242565941000 10101242566080077 10151242565941001 10111242566300321 10211242565766888 1007 cREVGeometrycache total 14order ì í ï ñ ò ó õ ö ÷ ø ù ý þ ÿ ì Field €@ \ · cREVTable currentview Function: accountancyFormat cREVGeneral revUniqueID 1242564885084 ê Function: accountancyFormat í Field €@ $Ô> · x cREVTable currentvscroll 0 viewablerows 37currentxmouseloc 112currenthscroll 0currentymouseloc 37scrollbarwidth 20 cellyspacing 13viewablecolumns 8rightfieldloc 616numbertabstops 1 cellxspacing 80 leftfieldloc 12topfieldloc 36currentview P
accountancyFormat([number],[rounded],[currency character],[thousands character],[decimal character])
This is a function to take a number and format it in the UK accountancy style. It has the following parameters:
number the number that you want to format (mandatory)
rounded true = rounds off to a whole number
false = rounds off to two decimal places
currency character
Where is the script?
You can find the script for the function in this stack's script. Copy and paste it into your own.
bottomfieldloc 506 cREVGeneral revUniqueID 1242564943920 ê eaccountancyFormat([number],[rounded],[currency character],[thousands character],[decimal character]) @ ÿÿ Blue @ ÿÿ Blue $ @ ÿÿ Blue % 9 @ ÿÿ Blue : O @ ÿÿ Blue P c d pThis is a function to take a number and format it in the UK accountancy style. It has the following parameters: 6number the number that you want to format (mandatory) ,rounded true = rounds off to a whole number * false = rounds off to two decimal places kcurrency character places an optional character in front of the formatted number (default is no character) Pthousands character changes the default comma to one character of your choosing Sdecimals character changes the default full stop character to one of your choosing ¶Note: All positive results will carry a trailing space character. Thus if you have a mixture of positive and negative results, they will all neatly line up in a right-aligned field. ¯ Where is the script? bYou can find the script for the function in this stack's script. Copy and paste it into your own. Example builder: QEnter numbers, characters and change checkboxes to see how the function behaves. P ï Label Field € _ q ´ cREVTable currentview Number: cREVGeneral revUniqueID 1242565766888 Number: ñ field_number -` € ‡^ ¸ Ö cREVGeneral revUniqueID 1242565789797 ê 3141652.9849 ò Label Field € { s ° cREVTable currentview Currency Character: cREVGeneral revUniqueID 1242565941000 Currency Character: ó field_currency -` € ‡z &