Jump to content

[SOLVED] Force MySQL to use decimal numbers instead of sci. notation


Recommended Posts

I am pulling data from a table and want the numbers to be output in decimal notation, but MySQL keeps outputting the numbers in scientific notation.

 

Is there a way (and I'm sure it's a simple one) to force MySQL to use decimal notation instead?

Outputting to command line.

 

The data gets inserted in, then some simple arithmetic when it gets pulled out.

 

I apologize, I don't have any test data for you to look at.

 

But apparently, my wife (the person with the problem), switched the data type to DEC from FLOAT and it worked fine, giving all returns in decimal notation.

 

Why would that be, I thought they were the same?

Outputting to command line.

 

The data gets inserted in, then some simple arithmetic when it gets pulled out.

 

I apologize, I don't have any test data for you to look at.

 

But apparently, my wife (the person with the problem), switched the data type to DEC from FLOAT and it worked fine, giving all returns in decimal notation.

 

Why would that be, I thought they were the same?

 

With no test data, not test output and no query... we're not going to get anyhere.

Well, the problem is no longer an issue, as it was 'fixed' by switching the data type from FLOAT to DEC.

 

Now I just want to satiate my curiosity, and for future reference.

 

But here is some sample data, the query, and some sample return data:

(Please note that bsyn and tsyn are basically the same tables with some differences in the Z values)

CREATE TABLE bsyn (
X FLOAT NULL,
Y FLOAT NULL,
Z FLOAT NULL,
) ;


INSERT INTO bsyn
VALUES ('455526.272000','1644214.016000','5613.504598')
, ('455529.088000','1644226.176000','5613.766831')
, ('455531.904000','1644238.208000','5614.029063')
, ('455534.720000','1644250.496000','5614.291295')
, ('455537.536000','1644262.656000','5614.553528')
, ('455540.352000','1644274.816000','5614.815760')
, ('455543.168000','1644286.976000','5615.077992')
, ('455545.984000','1644299.264000','5615.340224') ;


SELECT bsyn.X
, bsyn.Y
, bsyn.Z AS z1
, tsyn.Z AS z2
, bsyn.Z - tsyn.Z AS diff
FROM bsyn
, tsyn
WHERE bsyn.X = tsyn.X
AND bsyn.Y = tsyn.Y ;


+--------+--------------+---------+---------+------------------+
| x      | y            | z1      | z2      | diff             |
+--------+--------------+---------+---------+------------------+
| 456187 | 1.64708e+006 |  5797.5 |    5644 |  153.50244140625 |
| 456190 | 1.64709e+006 | 5798.31 | 5645.12 |   153.1904296875 |
| 456193 |  1.6471e+006 | 5799.12 | 5646.24 |   152.8779296875 |
| 456196 | 1.64711e+006 |    5800 | 5647.37 |  152.63623046875 |
| 456199 | 1.64712e+006 | 5800.88 | 5648.49 |  152.39501953125 |
| 456201 | 1.64714e+006 | 5801.76 | 5649.61 |  152.15283203125 |
| 456204 | 1.64715e+006 | 5802.64 | 5650.73 |   151.9111328125 |
| 456207 | 1.64716e+006 | 5803.52 | 5651.85 |   151.6689453125 |
| 456210 | 1.64717e+006 |  5804.4 | 5652.97 |  151.42724609375 |
| 456213 | 1.64719e+006 | 5805.28 | 5654.09 |    151.185546875 |
| 456216 |  1.6472e+006 | 5806.16 | 5655.21 |  150.94384765625 |
| 456218 | 1.64721e+006 | 5807.04 | 5656.33 |   150.7021484375 |
+--------+--------------+---------+---------+------------------+

From the manual:

 

The FLOAT and DOUBLE data types are used to represent approximate numeric data values.

The DECIMAL and NUMERIC data types are used to store exact numeric data values.

 

To be honest, I've never used FLOAT ever... so I guess I didn't know.

 

The easy way to cheat is the use CAST( field AS decimal) -- but only in MySQL 5 -- otherwise, use yourField+0, which forces an implicit converstion back to decimal.

 

HTH.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.