Best practice for storing weights in a SQL database?

前端 未结 3 846
心在旅途
心在旅途 2020-12-29 11:26

An application I\'m working on needs to store weights of the format X pounds, y.y ounces. The database is MySQL, but I imagine this is DB agnostic.

I ca

3条回答
  •  梦毁少年i
    2020-12-29 12:00

    First, I had not known about how floating point numbers were inaccurate - thankfully a search latter helps me understand: Floating Point Inaccuracy Examples

    I would fully agree with @eggyal - keep the data in a single format in a single column. This allows you to expose it to the application and let the application deal with the presentation of it - be it in lbs/oz, rounded up lbs, whatever.

    The database should keep the raw data while the presentation layer dictates the layout.

提交回复
热议问题