cancel
Showing results for 
Search instead for 
Did you mean: 

SELECT TO_DECIMAL(42242.640972,15,15) "to decimal" FROM DUMMY;

aj_shaik
Explorer
0 Kudos

Dear Experts,

Can somebody help me understand why

SELECT TO_DECIMAL(42242.640972,15,15) "to decimal" FROM DUMMY;

does not work and throws numeric over flow exception.

Thank you for your time

Kind Regards,

Ajaz

Accepted Solutions (0)

Answers (3)

Answers (3)

aj_shaik
Explorer
0 Kudos

Dear Lars, Dear Mert,

Thank you for your reply. I will try with some examples and understand how it works.

Kind Regards,

Ajaz

lbreddemann
Active Contributor
0 Kudos

Floating point numbers are not a particularly intuitive concept in general.

So it might be useful to get familiar with them on a broader basis, e.g.:

The Floating-Point Guide - What Every Programmer Should Know About Floating-Point Arithmetic

and of course

https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf

mert_karakilic
Participant
0 Kudos

You need to add more to the second set of digits for the space. Imagine 1st set of digits as the total digits and second set is the part after the fraction there. So in your case you defined 15,15. As Lars said, you have not left any for the numbers before the fraction. Try 20,15, it works fine.

SELECT TO_DECIMAL(42242.640972,20,15) "to decimal" FROM DUMMY;


Even 19 works but not sure why?

lbreddemann
Active Contributor
0 Kudos

You specified to have all 15 digits reserved for the fractional part but the value you try to convert here does have 5 digits before "the dot'. That's why you get the error message.

See Data Types - SAP HANA SQL and System Views Reference - SAP Library on how DECIMAL data types work.