daydreamer Posted September 25, 2008 Share Posted September 25, 2008 I am using a Mysql database, and need to store numbers similar to these: 1.32, 22.23, 99.99, 0.00. Can I use "smallint" as the data type? I could use the "decimal" type, but in the mysql manual it shows numbers like this 1.2342324323, all i need is two decimal places! Thanks. Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/ Share on other sites More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 An "Integer" is a whole number, like 1, 37, or 1,452,854. Use the decimal type and use a round function (either in PHP or SQL) to round it off to two decimal places. Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650487 Share on other sites More sharing options...
daydreamer Posted September 25, 2008 Author Share Posted September 25, 2008 ok, thanks. how can i set it up so any numbers from 0.00 to 999.99 can be entered? from the mysql manual: salary DECIMAL(5,2) this allows 99999.99. So i need (3,2). I am using phpmyadmin to create the column, do I just place "3,2" (without marks) into the "Length/Values" when creating the column? Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650491 Share on other sites More sharing options...
aebstract Posted September 25, 2008 Share Posted September 25, 2008 Yes, just enter 3,2 Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650492 Share on other sites More sharing options...
Barand Posted September 25, 2008 Share Posted September 25, 2008 Enter 5,2 (5 digits, 2 of them decimals) Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650648 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Enter 5,2 (5 digits, 2 of them decimals) ok, thanks. how can i set it up so any numbers from 0.00 to 999.99 can be entered? ... So i need (3,2). Way to confuse the poor kid Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650655 Share on other sites More sharing options...
Barand Posted September 25, 2008 Share Posted September 25, 2008 May be confusing but DECIMAL(3,2) only takes values up to 9.99 Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650666 Share on other sites More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 the 3 is total length, and the 2 is decimal places. If you wanted up to 999.99, it should be 5,2. Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650668 Share on other sites More sharing options...
Barand Posted September 25, 2008 Share Posted September 25, 2008 Thought that was what I said ??? Enter 5,2 (5 digits, 2 of them decimals) Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650670 Share on other sites More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 Heh... serves me right for only reading the previous post. Yes, what Barand said! Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650672 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Eeep, didn't know it worked like that. My apologies. Link to comment https://forums.phpfreaks.com/topic/125798-does-smallint-allow-decimal-numbers/#findComment-650702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.