Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# MySQL Anomaly with DECIMAL fields

Posted on 2012-04-12
Medium Priority
357 Views
To keep this short and simple, please look at the following two lines to reproduce the problem. I need a solution to store this information NOT floating calculations that trail off into random forever-ness (see my other questions which is why I am using DECIMAL(10,2) in the first place).

Problem is simple. There is an amount being queried from one of my tables for 2479 that requires some calculation, and then insert into another table. Both tables have the field as DECIMAL(10,2) to fix the FLOATing point issues as outlined in my previous post.

The following line of code will reproduce the issue without need for any tables
``````SELECT CAST(FORMAT(CEIL((2791/1.13) * 100)/100,2) AS DECIMAL(10,2));
``````

Why does it not return this amount that the following line returns ??
``````SELECT FORMAT(CEIL((2791/1.13) * 100)/100,2);
``````

0
Question by:microvb
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 3

Accepted Solution

microvb earned 0 total points
ID: 37839947
Interesting,

It works when I do this >>

``````SELECT CAST((CEIL((2791/1.13) * 100)/100) AS DECIMAL(10,2));
``````
0

LVL 3

Author Closing Comment

ID: 37839952
Problem resolved. Dunno why, but it works --- so..... meh!
0

LVL 84

Expert Comment

ID: 37839957
The comma ',' generated by the FORMAT statement is causing an error in the DECIMAL statement.  If you use
``````SELECT CAST((CEIL((2791/1.13)*100)/100) AS DECIMAL(10,2));
``````

it will work.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.