Martin
Martin

Reputation: 2017

Proper field type for numbers to ORDER BY?

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.

Upvotes: 0

Views: 38

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191739

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.

Upvotes: 1

jap1968
jap1968

Reputation: 7763

You can choose:

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

You can find additional info on the corresponding mysql documentation

Upvotes: 2

Related Questions