in reply to printf exact field width of floating point number
Your question implies that you are willing to lose precision in order to fit within the number of spaces? This is rather bizarre because a fixed field number format like you describe is rare - more common even in 'C' is a space separated number field.
Perl does have the sprintf() function. That may help. Sounds like you want to print a number, if that number cannot "fit", then truncate digits, then if it still can't fit, then use exponential notation. Try sprintf() with %f format, if that is too long, then switch to %g format.
|
|---|