Hello to all,
I'm working on a file that contains a series of decimal values with different precision.
I need to divide these numbers by 100 and I don't need to round.
Decimal numbers represented by a binary system are ALWAYS rounded / subject to rounding. For example, your first number, given as 0.123456789012 , is internally approximated / stored as 0.123456789011999995553381381796 , which itself is a rounded value already. You may end up less than or greater than your target value, or, in rare cases, exactly on target (0.5, or 0.25, for example).
So, your request is a bit diffucult to fulfill. You can try awk 's OFMT variable set to a fixed output field length, but, surprise, additional undesired decimal places occur:
This works as there are two additional places needed for the division by 100, but length ($1) already counts two characters: the leading 0 and dot. If you have more significant leading digits, additional measures / steps need to be taken.
This might possibly be done for the range of numbers noted by parsing the numbers, inserting 2 zeros, and so avoiding any arithmetic whatsoever -- just a thought ... cheers, drl