I am having to grab some data from an Oracle database via Groovy script and dump it into a flat file to upload to a bank for EFT payments.
The data is stored in the database as NUMBER(15,2) - it represents a dollar value.
The bank expects the number to be written out as a string, without the decimal.
My thought was to read the value from the database ($528.10) and store it in a float - which seems to work.
In order to output the value as 0000052810 (value is 10 characters, assuming 8 digits for dollars and last 2 digits for cents) I thought I'd try this.
x1 = 528.1
x2 = x1 * 100
However multiplying the float by 100 is giving me rounding errors.
I added output of the two values:
Which gave me:
I could add: x3 = x2.round() to make the output 52810 - but since I'm dealing with financial information here, I'd rather get an exact conversion than rely on rounding. Anyone able to offer me a clean solution to this ?