如何为单位转换建立表格模型? [英] How do you model a table for unit conversion?

查看:149
本文介绍了如何为单位转换建立表格模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要创建一个各种单位的数据库模型及其彼此之间的关系。例如,36英寸= 3英尺= 1码= 0.9144米等。该表还将存储盎司,磅,kg,克,厘米的杯子和各种测量。

I'm looking to create a db model of various units and their relation to each other. For instance, 36 inches = 3 feet = 1 yard = .9144 meters etc. This table would also store cups in ounces, pounds, kg, grams, cm and all sorts of measurements.

如何做到这一点?我在想这样的事情:

How do you do this? I was thinking about something like this:


Amount | Units | ConversionFactor | ConversionUnits
1      | foot  | 12               | inches
1      | yard  | 36               | inches

但是坦率地说,这似乎是一个可怕的想法。试图弄清楚在一个院子里有多少英尺会非常复杂,我不认为我可以存储所有我需要的转换。

But frankly, this seems like a terrible idea. Trying to figure out how many feet in a yard would be very convoluted, and I don't think I could ever store all the conversions I need.

还有什么其他想法?我知道这是一个解决的问题。感谢!

What other ideas are there? I know this is a solved problem. Thanks!

推荐答案

存储转换为SI单位,而不是其他非公制单位。然后你可以在单位之间转换,而不需要知道显式转换。

Store conversions to SI units, not to other non-metric units. Then you can convert between units in without needing to know the explicit conversion.

Unit         | Class      | Base Unit Multiplier
------------------------------------------------------
foot         | length     | 0.304800610
yard         | length     | 0.914401830
square foot  | area       | 0.092903040
...

所以14码的码是:

14 feet * 0.304800610 = 4.26720854 meters
4.26720854 meters * 0.914401830⁻¹ = 4.66666667 yards

这篇关于如何为单位转换建立表格模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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