Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function like "sprintf" for formatting numeric output

Status
Not open for further replies.

avanderlaan

Programmer
Jul 11, 2002
156
I'm looking for a function like "sprintf" in C that creates string representations of numeric values according to a user-defined specification. For example

floating point: sprintf( string, "%1.5f", aFloat ) produces ".12345" where aFloat = 0.123451234512345...

scientific notation: sprintf(string, "%1.5e", aFloat ) produces 1.23451e-1

Thanx.
 
You can try the format function. similar to the one below.

Format(variable,"#,###,##0.00")

Examples,

Format(34,"#,###,##0.00")=34.00
Format(.12234,"#,###,##0.00")=0.12

Beware of rounding of decimal values. Thanks and Good Luck!

zemp
 
Thank you, Zemp. I can use that as a starting point for representing scientific notation too (some of my exponents are in the e-14 range).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top