# ba_sprintf

Definition: | string s = ba_sprintf(sequence fmt, bigatom N)
Description: | Get formatted string (%B) representation of a bigatom. Similar to sprintf(), except that it replaces a single %B formatting specification. The format string is formally declared as follows: fmt = '%' [','] ['+'] [fchar] [size] [['.'] ['0'] [decs] ['a' | [char] 'c'] ['e'|'E'] ] 'B' where ',' means comma-separate (eg "1,000,000") the integer part of the result, '+' means always put the sign, fchar, if not '1'..'9', is the fill character, size is the minimum size of the integer portion of the number, '.' merely serves to separate the parts of the format string decs is the maximum number of decimals to show 'a' zero fills decimal places, 'c' (ignored if size not specified) allows an alternate fill character 'e' use exponential format, with an 'e' 'E' use exponential format, with an 'E'
Comments: | You may need to experiment a little to get things right. I could only find a few example uses, and will freely admit to not being very sure about the ['0'] ['a' | [char] 'c'] bits. The original author notes this is somewhat ad-hoc and possibly deserves to be rewritten. I would say that it seems to be fairly cleanly written code, not that I fully grasp all the nuances of it, and any difficulties lie in redesigning the format specification, rather than the implementation. Just like printf()/sprintf(), ba_printf() is a simple wrapper of ba_sprintf(), with an additional file parameter at the start.
Example: |
    include bigatom.e
    {} = ba_scale(50)
    bigatom ba = ba_sqrt(2)
    ba_printf(1,"The square root of 2 with 50 decimals is:%.50aB\n",ba)
    -- The square root of 2 with 50 decimals is:1.41421356237309504880168872420969807856967187537694