Repository navigation
Modern String MoneyFormat
Paul Squires edited this page Oct 14, 2026
·
4 revisions
Home › String Library › String Library › MoneyFormat
Renders an amount the way the user's locale writes money. Assign a numeric value, set the properties you care about, read back the string. Every characteristic the locale specifies can be overridden or suppressed individually.
dim as MoneyFormat m = <int64 | float64 | Currency | Decimal>
m.<property> = <value>
print m.ToString( )- In
std/money(moneyformat.tiko), notstd/strings. It is the one member of this library that is a TYPE, because it carries state a function would need six arguments for. - Whatever you assign becomes a
money.Decimal, so there is one render path and one rounding rule. Integers andCurrencywiden exactly; afloat64does not, because a double is not exact to begin with. - An invalid
Decimalrenders as the empty string rather than as0.00. - Settings:
Symbol,DecimalPoint,ThousandsSep,Grouping,FracDigits,SymbolPrecedes,SpaceBySymbol,Negative,BlankIfZero,ZeroText,ForcePlus,Rounding. A getter reports the EFFECTIVE value: your override if you made one, otherwise the locale's. - Setting a property ALWAYS marks it as yours, so
m.Symbol = ""SUPPRESSES the symbol. Only UseLocale gives it back.FracDigits = -1is the numeric spelling of the same thing. - Rounding is half-even by default, matching
money.Decimaland the rest ofstd/moneyso the printed figure never disagrees with the computed one.Rounding = DEC_HALF_UPgives the accounting and Windows convention. - Overrides are per instance and never touch the process locale.
- About 96 bytes; it touches the heap only for the string it produces.
#import "std/money"
using money
dim as MoneyFormat m = DecimalParse( "-1234.5" ).Value( )
print m.ToString( ) '' -$1,234.50 on en-CA
m.Negative = MONEY_NEG_PARENS
print m.ToString( ) '' ($1,234.50)
m.ThousandsSep = "" '' SUPPRESSED, not "use the locale"
print m.ToString( ) '' ($1234.50)
m.UseLocale( MONEY_F_THOUSANDSSEP ) '' back to the locale's separator
'' a ledger column: blank zeros, parenthesised negatives, no grouping
dim as MoneyFormat cell = someCurrency
cell.BlankIfZero = true
cell.Negative = MONEY_NEG_PARENSLibrary: String Library
Category: String Library
Documented under: Money Formatting
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing