Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Float data type in javascript

 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this is my jsfiddle

JS Fiddle

now my aim is If user left the field empty then 0.00 fills in auto*. and if the entered string is integer then .00 is automatically appended to the string.

I can perform all from my above script but when I again TAB the field then an extra .00 is appended to it.

What is wrong with this please explain.

Thanks In Advance!!!
 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check if there is already a value before you append the ".00"? ... Wait I think you did that. OK You seemed to get the position of the "." decimal but you didn't use it. Maybe checking if the existing value has a decimal before appending.
 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe checking if the existing value has a decimal before appending.


Yes exactly this is what I am searching.

Is there any string function which results boolean type.

But I think my script is correct, because first it checks if it is empty if yes then it append value 0.00 which is float, then why script is going into "if(for float checking)", this I am not getting???

Please Help..!!!
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1820
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're making this very difficult.

If the requirements truly are:

(1) If user left the field empty then 0.00 fills in auto
(2) if the entered string is integer then .00 is automatically appended to the string.

Why not approach them in that order?

http://jsfiddle.net/6ff93/3/

Note: What should happen the input contains letters? (Or anything that doesn't parse into a float or int?)
 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks " Michael Matola "....could not think of that.
Thank you again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic