0

I am trying to add 0.01 to a variable which has been taken by servlet. I use this variable in jsp form but after adding there is a little problem. This is some part of my code and results.

<input type="number" name="bid_price" placeholder="9,99" min="${auction.currently + 0.01}" value="${auction.currently + 0.01}" step="0.01"/>

If i use only the variable, the output is correct (e.g. 0.12). When i add 0.01 insead of 0.13 i have as a result 0,129999997317791.

Can you help me to fix that little error?

Mindaugas
  • 885
  • 9
  • 12
  • How are you passing value from servlet? Can you provide that code? – Naman May 29 '15 at 09:49
  • You don't need that part of code. What can i say is that ${auction.currently} is a float. – Νίκος Διαμαντόγιαννης May 29 '15 at 09:55
  • 2
    You can see for your self that you are adding float to 0.01 so resulting value would be `double` not `float`. – Naman May 29 '15 at 10:00
  • So you tell me that 0.01 is a double? I don't think you really know the difference between double and float. Check this and make t clear to your mind http://stackoverflow.com/questions/2386772/difference-between-float-and-double – Νίκος Διαμαντόγιαννης May 29 '15 at 10:51
  • As @NaMaN mentioned. You will get a *Double* if you add *Float* to anything except *BigInteger* in [tag:el]. Refer to: Section 1.7.1 in [Expression Language Specification](http://download.oracle.com/otndocs/jcp/jsp-2.1-fr-eval-spec-oth-JSpec/). – Mindaugas May 29 '15 at 11:27
  • In java if you want compiler to consider 0.01 as `float` than you have to pass `f` like `0.01f` otherwise it will be considered it as double. – Naman May 29 '15 at 11:31

0 Answers0