jpeterson579's avatar

Data type for all numbers. ex: 2, 3.3, -2.890, 01, etc

Trying to create my database but I cant figure out what data type to label a specific field in my migration.

I want the field to store numbers like 2, 3.3, -2.890, 01, etc... However, I dont want to enforce every number must have a certain amount of decimal places.

Any thoughts?

0 likes
7 replies
jlrdw's avatar

In MySQL I use decimals for something like that.

click's avatar

If you want values like you say: 01 (with a leading zero) any decimal/float/double field is not applicable.

ejdelmonico's avatar

Have you thought about just using a string and then convert them in code? Otherwise, you might want to search for a plugin because the standard install of MySQL or MariaDB doesn't give you a way to include all of the variances you require to the best of my knowledge. INT is probably the closest.

rawilk's avatar

@jpeterson579 you can do comparisons on strings like that, but you're better off casting them first to a numeric data type and then comparing them.

jlrdw's avatar

01? Justice store 1. You can format this stuff anyway you want at runtime.

It almost sounds like you don't need numbers at all just strings I mean 01.

Please or to participate in this conversation.