克,毫克,微克和千焦耳的最佳mysql数据类型 [英] Best mysql datatype for grams, milligrams, micrograms and kilojoule

查看:206
本文介绍了克,毫克,微克和千焦耳的最佳mysql数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对数据库的数据类型非常怀疑,我需要使用不同的度量单位,因为我具有不同的元素和不同的标度,并且我确定所使用的限制是因为我从标准元素中选取了这些限制,但是我怕品种.

只是考虑到我使用100克产品并从中提取所有元素,因此,我敢肯定我不能超过100克蛋白质,但是我可以达到3500千焦耳或3.27毫克铁元素.

I'm very dubious about datatype of my database, I need to use different unit of measurements because I have different elements and different scales, and I'm sure about the limits used, because I take them from standard elements, but I'm afraid about the variety.

Just consider I work with 100 grams of product and take from it all elements, so, I'm sure I can't go over 100 grams for proteins, but i can reach 3500 kilojoule or 3,27 milligrams of iron element.

我想我需要各种数据类型,但是我不确定正确的数据类型.
我将显示最大值以更清楚地了解单位限制:

So I need various datatypes I think, but I'm not sure about the right kind.
I'll show the max values to be more clear about the unit limits:

grams          99,99 g
milligrams   9999,99 mg
micrograms  99999    µg
kilojoule    9999    kj

那么,正确的方法是什么?
我敢肯定,最好的方法(最好的性能)是将各种元素与它们的标准值一起存储(例如,卡路里的千焦耳),但是等效的数据类型是什么?

So, what is the right way?
I'm sure the best way (the best performance) is to store the various elements with their standard values (for example, kilojoule for calories) but what are the datatype equivalents?

推荐答案

对于当前版本的MySQL中最大为999999.9999的十进制,您需要将字段定义为:

For a 999999.9999 max decimal in the current version of MySQL, you would need to define field as:

DECIMAL (10, 4)

(它很容易与DECIMAL(6,4)混淆,在旧版本的MySQL中,是正确的,但最新的是不正确的)

(it's easily confused with DECIMAL (6, 4) which was correct in older versions of MySQL, but is incorrect on the latest)

看到:

Decimal(3,2)值在MySQL中始终为9.99

M,D是十进制是什么意思( M,D)到底是什么?

这篇关于克,毫克,微克和千焦耳的最佳mysql数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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