如何在MySQL中存储科学计数法数字 [英] How do you store scientific notation numbers in MySQL

查看:1984
本文介绍了如何在MySQL中存储科学计数法数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySql中存储科学计数法数字.

I want to store scientific notation numbers in MySql.

我已经将它们保存到数据类型为decimal的字段中.问题是它以常规表示法存储它(至少是当我在MAMP附带的Web控制台中查看数字时看上去的样子),因此您需要为该字段分配更多字节...我相信这会导致拥有一个非常大的数据库.

I've saved them to a field which has datatype decimal. The issue is that it stores it in normal notation (at least that what it seems when I view the number in the web console that comes with MAMP) and thus you need to allocate more bytes to the field ... which I believe will lead to having a very large database.

无论如何,仍然可以按原样存储科学计数法(信息单元要少得多),但是仍然能够进行数值计算,例如<和>(最后一条注释的上下文是,如果您只需要显示该值,则可以将其存储为文本类型,但这对我来说不行).

Is there anyway to store the scientific notation as is (far fewer units of information), but still be able to do numeric computations e.g. < and > (context for the last comment is that if you just needed to display the value you could store it as a text type, but that won't do for me).

推荐答案

FLOATDOUBLE数据表可以使用科学计数法显示(并插入):

FLOAT and DOUBLE datataypes can be shown (and inserted) using Scientific notation:

CREATE TABLE numSC
( f float
, d double
) ;

INSERT INTO numSC
VALUES
(POW(10,30), POW(10,30)) ;

INSERT INTO numSC
VALUES
(10.1234567890123456e-20, 10.1234567890123456e-20) ;

SELECT * FROM numSC ;

>  |         f    |                  d    |
>  |       1e+030 |                1e+030 |
>  | 1.01235e-019 | 1.01234567890123e-019 |

这篇关于如何在MySQL中存储科学计数法数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆