문제

What's the proper field type for numbers in MySQL?

I have a field with numbers like 0.00, 4.12, 99.10, 130.99

So TINYINT or SMALLINT are not valid since they remove the decimal places to 0, 4, 131 etc.

When I cose VARCHAR I cannot properly ORDER BY because it sorts 99.10 after 130.99

Which type do I need? Highest number will not be larger than 1000.

도움이 되었습니까?

해결책 2

DECIMAL

Column syntax:

`name` DECIMAL(<precision>,<scale>)

Note that <precision> is the total column length, so DECIMAL(5,2) is 3 digits before the decimal and 2 after.

다른 팁

You can choose:

  • Fixed-point: Decimal, numeric
  • Floating-point: Float, double

You can find additional info on the corresponding mysql documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top