Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double to string conversion

 
rutuja patil
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rutuja patil
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
price is of double type.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Showing the JSP source is useless. The HTML being sent to the browser is what is of interest.
 
rutuja patil
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. one more question- which type will be better choice for currency?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends upon a number of factors, but you need one that doesn't lose precision the way that double does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic