Question

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.

Was it helpful?

Solution 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.

OTHER TIPS

You can choose:

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

You can find additional info on the corresponding mysql documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top