aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes double to string conversion 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 "double to string conversion" Watch "double to string conversion" New topic
Author

double to string conversion

rutuja patil
Greenhorn

Joined: Dec 17, 2009
Posts: 23
on jsp page there is price var with 0.0003 value

and on javascript I am accessing that variable using the following code:

output: alert(3E-4)
javascript converts pr.value to 3E-4.
but I want the string value 0.0003 .
Is there any way to convert double to string in javascript?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

What kind of element is "Price"? If it's a form control, the value is already a string and the conversion likely happened during the HTML generation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rutuja patil
Greenhorn

Joined: Dec 17, 2009
Posts: 23
price is of double type.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

There's no such thing in JavaScript. If you are not going to answer the questions posed to you, it's going to be hard to help you.

Look at the View Source in the browser. Is the value of that element already converted to the wrong format?

How are you setting the value of the element in the JSP?

And, by the way, a double is a really poor choice to represent a currency value.
rutuja patil
Greenhorn

Joined: Dec 17, 2009
Posts: 23
I am sorry Bear Bibeault,I didn't understand the question before.now I got it what you tried to ask.
following is the original code of JSP:

output: $0.0003

In above code price is field(double type) of promo object. I use Spring framework for my application.

after reading your message I modified the code to display the original value of object

output: 3.0E-4

After modification it was showing 3.0E-4.
Please let me know if you need any more details.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Showing the JSP source is useless. The HTML being sent to the browser is what is of interest.
rutuja patil
Greenhorn

Joined: Dec 17, 2009
Posts: 23
I looked at the View Source in the browser. The value of that element is already converted to the wrong format and it is 3.0E-4.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Then the problem is on the server. You'll need to make sure that the value is converted in the manner you desire in your JSP.
rutuja patil
Greenhorn

Joined: Dec 17, 2009
Posts: 23
Thanks for your reply. one more question- which type will be better choice for currency?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Depends upon a number of factors, but you need one that doesn't lose precision the way that double does.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: double to string conversion