O
Ouroborus777
I've been messing around with printing floats. It seems that printf()
is only capable of printing the fractional portion at a fixed length.
Is there some way to print floats such that the full fraction is shown
but without the trailing zeroes? I realize that this could be an
exercise in string manipulation (ie: stringify the float giving a
length that's longer than the float could possibly be then trim the
trailing zeroes) but I would prefer to do this as modification
What I have ("%.16e"):
-9.0673828125000000e-001
-4.9169921875000000e-001
-4.2138671875000000e-001
-3.6889648437500000e-001
-2.4206542968750000e-001
-2.0385742187500000e-001
0.0000000000000000e+000
4.3029785156250000e-003
4.4750976562500000e-001
7.2753906250000000e-001
7.8857421875000000e-001
8.7060546875000000e-001
8.7890625000000000e-001
8.9794921875000000e-001
8.7011718750000000e-001
What I would like:
-9.0673828125e-1
-4.9169921875e-1
-4.2138671875e-1
-3.68896484375e-1
-2.420654296875e-1
-2.03857421875e-1
0 (or 0.0, or 0.0e+0, but I would prefer just 0)
4.302978515625e-3
4.47509765625e-1
7.275390625e-1
7.8857421875e-1
8.7060546875e-1
8.7890625e-1
8.9794921875e-1
8.701171875e-1
So, any suggestions or maybe point me to some code?
is only capable of printing the fractional portion at a fixed length.
Is there some way to print floats such that the full fraction is shown
but without the trailing zeroes? I realize that this could be an
exercise in string manipulation (ie: stringify the float giving a
length that's longer than the float could possibly be then trim the
trailing zeroes) but I would prefer to do this as modification
What I have ("%.16e"):
-9.0673828125000000e-001
-4.9169921875000000e-001
-4.2138671875000000e-001
-3.6889648437500000e-001
-2.4206542968750000e-001
-2.0385742187500000e-001
0.0000000000000000e+000
4.3029785156250000e-003
4.4750976562500000e-001
7.2753906250000000e-001
7.8857421875000000e-001
8.7060546875000000e-001
8.7890625000000000e-001
8.9794921875000000e-001
8.7011718750000000e-001
What I would like:
-9.0673828125e-1
-4.9169921875e-1
-4.2138671875e-1
-3.68896484375e-1
-2.420654296875e-1
-2.03857421875e-1
0 (or 0.0, or 0.0e+0, but I would prefer just 0)
4.302978515625e-3
4.47509765625e-1
7.275390625e-1
7.8857421875e-1
8.7060546875e-1
8.7890625e-1
8.9794921875e-1
8.701171875e-1
So, any suggestions or maybe point me to some code?