GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes Float data type in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Float data type in javascript" Watch "Float data type in javascript" New topic
Author

Float data type in javascript

Saumitra Tiwari
Greenhorn

Joined: Apr 09, 2014
Posts: 28
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

Joined: Sep 13, 2007
Posts: 2452
    
    8

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Saumitra Tiwari
Greenhorn

Joined: Apr 09, 2014
Posts: 28
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

Joined: Mar 25, 2001
Posts: 1747
    
    2
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
Greenhorn

Joined: Apr 09, 2014
Posts: 28
Thanks " Michael Matola "....could not think of that.
Thank you again.
 
GeeCON Prague 2014
 
subject: Float data type in javascript