I have a very peculiar situation happening while doing a simple division using GoogleSQL.
For example, variables involved:
Fruit_name -- String
price_purchased -- String
used_discount -- double
Example values:
fruit_name | price_purchased | used_discount |
---|---|---|
apple | 5 | 0.8 |
pear | 6 | 0.76 |
A simple division through SQL to find out original price:
SELECT DISTINCT
fruit_name,
CAST(price_purchased AS double),
used_discount,
CAST(price_purchased AS double) / (1 - used_discount) as original_price
FROM
fruit_table
I'm weirdly getting such a result:
fruit_name | price_purchased | used_discount | original_price |
---|---|---|---|
apple | 5 | 0.8 | 25.000000000000007 |
pear | 6 | 0.76 | 25 |
The original price for the apple should also give me a value of 25 exactly, just like how the pear's value was also at 25.
How is it that the value of the apple's original price could have that weird minuscule amount? Is this due to some type casting issue?
Thanks.