Solved

MySQL Anomaly with DECIMAL fields

Posted on 2012-04-12
3
353 Views
Last Modified: 2012-04-12
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));

Open in new window


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

Open in new window


Thanks in advance.
0
Comment
Question by:microvb
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
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));

Open in new window

0
 
LVL 3

Author Closing Comment

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

Expert Comment

by:Dave Baldwin
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));

Open in new window


it will work.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question