I'm trying to figure out how SQL arithmetic involving decimals is giving an integer result. I've put together a sample query that replicates my question.

with Values as (
select cast(1.5267 as decimal(31,4)) as A, cast(1.6 as decimal(12,4)) as B
from SYSIBM.SYSDUMMY1
)
select Values.*, (A - B) / B * 100.00 as RESULT
from Values;

This gives: 1.5267 1.6 0


The RESULT column has a type of decimal(31,2), but the value is zero. With a precision of 2, RESULT should actually be -4.58.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.