CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Number formatting

Integers, money and times as text, without printf. More...

Functions

char * fmtInt (char *p, int32_t v)
 Write an integer: "-123".
 
char * fmtMoney (char *p, int32_t v)
 Write an amount of money: "$1234", "-$5".
 
char * fmtCash (char *p, int32_t v)
 Write money with thousands separators: "$1,234".
 
char * fmtShort (char *p, int32_t v)
 Write money short for a narrow space: as fmtMoney(), but "$12K" from $10,000.
 
char * fmtTime (char *p, uint16_t secs)
 Write a time as minutes and seconds: "1:05".
 
char * fmtStr (char *p, const char *s)
 Copy a string.
 

Detailed Description

Integers, money and times as text, without printf.

Each call writes at p, terminates the string and returns the new end, so calls chain:

char buf[16], *p = buf;
p = fmtStr(p, "BET "); p = fmtMoney(p, bet); // "BET $25"
char * fmtStr(char *p, const char *s)
Copy a string.
char * fmtMoney(char *p, int32_t v)
Write an amount of money: "$1234", "-$5".

The caller's buffer must be big enough: 12 characters hold any int32_t.

Function Documentation

◆ fmtInt()

char * fmtInt ( char *  p,
int32_t  v 
)

Write an integer: "-123".

Parameters
pWhere to write.
vThe number.
Returns
The end of the string (at its terminating 0).

◆ fmtMoney()

char * fmtMoney ( char *  p,
int32_t  v 
)

Write an amount of money: "$1234", "-$5".

Parameters
pWhere to write.
vDollars.
Returns
The end of the string.

◆ fmtCash()

char * fmtCash ( char *  p,
int32_t  v 
)

Write money with thousands separators: "$1,234".

Parameters
pWhere to write.
vDollars.
Returns
The end of the string.

◆ fmtShort()

char * fmtShort ( char *  p,
int32_t  v 
)

Write money short for a narrow space: as fmtMoney(), but "$12K" from $10,000.

From 10,000 on (either sign) it writes whole thousands, rounded toward zero: 12,999 is "$12K".

Parameters
pWhere to write.
vDollars.
Returns
The end of the string.

◆ fmtTime()

char * fmtTime ( char *  p,
uint16_t  secs 
)

Write a time as minutes and seconds: "1:05".

Parameters
pWhere to write.
secsSeconds.
Returns
The end of the string.

◆ fmtStr()

char * fmtStr ( char *  p,
const char *  s 
)

Copy a string.

Parameters
pWhere to write.
sThe string.
Returns
The end of the copy.