0

I have a query that will get the sum of some columns in my postgres database.

def total = Funds.executeQuery("SELECT SUM(a.FundA), SUM(a.FundB), SUM(a.FundC), SUM(a.FundA+a.FundB+a.FundC) FROM Funds a")

Given that FundA, FundB and FundC is defined as double.

Values: (Sample Only)

FundA = 233.343
      = 3.234
      = 324.23423

FundB = 32423.4234
      = 43.434
      = 234.234

FundC = 234.2342
      = 343.4345
      = 23423.3434

Query Result:

[560.81123, 32701.0914, 24001.0121, 57262.914730000004]

The sum of FundA, FundB and FundC is correct but the overall total is not trailing zero's with four at the end is not quite right.

Actual Result: 57262.914730000004
Expected Result: 57262.91473

How can I get the exact over all sum of the 3 columns? Without rounding off. Thank you

newbie
  • 119
  • 15
  • @doelleri it helps me to understand my problem a little bit. One of the solutions given is to use an exact data type for dealing with money, decimal. I am sure that i already used BigDecimal and the result is the same. – newbie Jun 14 '17 at 06:45
  • Is the BigDecimal mapped to a NUMERIC column type on the database? – doelleri Jun 14 '17 at 13:14

0 Answers0