0

I have a field in MySql Decimal(10,2) and I am trying to insert a float value like 1.1 in it. Unfortunately it is storing that value as 1.10. How can I store that value as it is, because the system will not be able to distinguish between 1.1 and 1.10.

Due to some reason I cannot change the Data Type to VARCHAR OR STRING. On the server side I am using php.

Any help would be greatly appreciated.

SpiderCode
  • 10,062
  • 2
  • 22
  • 42
Ricky
  • 35
  • 1
  • 10
  • This seems a presentation tier concern - why not leave the value in the database as a Decimal, but then when presenting the data to the user, cast it to [float or rtrim it](http://stackoverflow.com/a/5149186/314291) in php?. – StuartLC Feb 12 '14 at 06:06
  • If i use float or rtrim function it will discard 0 from both 1.1 and 1.10 Leaving 1.1 for both entries – Ricky Feb 12 '14 at 06:21
  • It seems you are trying to audit what the user typed in (? e.g. certainty of precision). I would then add an additional `varchar` column to store this, although for all numeric purposes, I would also keep the Decimal column. – StuartLC Feb 12 '14 at 06:25
  • Yes I am trying to store what ever user enters, The user can enter 1 or 1.1 or 1.10, But we do not have any other data type to deal such issues in MySql? – Ricky Feb 12 '14 at 06:39

2 Answers2

0

Your specification Decimal(10,2) is forcing it to save as a 2 place decimal. You can either use another data type like float OR you can trim it in your code using rtrim:

rtrim($value, 0);
Hass
  • 1,628
  • 1
  • 18
  • 31
  • If i use float dataType, I think it will not work because it will store 1.1 as 1.1, And 1.10 as 1.1, And on the other hand if i use rtrim function it will discard 0 from 1.1 and 1.10 Leaving 1.1 for both entries – Ricky Feb 12 '14 at 06:15
0

1.1 and 1.10 are both the same or do you have any other specification