excelでは、「-.12」のように入力しても「-0.12」のように変換されることは知っていましたが、mysqlでも同様?のことができるとは驚いた。
create table test_val ( id int primary key AUTO_INCREMENT, val decimal(5,2) ); insert into test_val (val) values(-.12); select * from test_val;
実行結果
mysql> create table test_val (
-> id int primary key AUTO_INCREMENT,
-> val decimal(5,2)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> insert into test_val (val) values(-.12);
Query OK, 1 row affected (0.00 sec)
mysql> select * from test_val;
+----+-------+
| id | val |
+----+-------+
| 1 | -0.12 |
+----+-------+
1 row in set (0.01 sec)perlのRegexp::Common::numberで、「-.12」をdecimalと判定する正規表現を作成しようとしましたが、できませんでした。やはり整数部のない小数は分かりづらいと思う。