SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 30th, 2001, 05:42 AM
gappelman gappelman is offline
Balance is everything!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 44 gappelman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Question Converting a number to decimal?

I use this bit of Java to convert a number, but I need to break the number (format) into decimal spaces.

Code:
<body onload="euroconv()">

<script language="JavaScript">
function euroconv() {
document.convert.esc.value=Math.round(document.convert.result.value)* 350;
document.convert.temp.value=Math.round(document.convert.esc.value)/ 200.482;
}
</script>

<form name="convert">Pound
<input name="result" value="1"><br>
<input type="hidden" size="6" name="esc">Euro
<input name="temp">
</form>


I need to format "temp" to look like this: 70,000,000
Instead of this: 70000000

Thank's
Gerard

Reply With Quote
  #2  
Old October 30th, 2001, 07:09 AM
ehsiung ehsiung is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Pittsburgh, PA
Posts: 3 ehsiung User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
java.text.DecimalFormat can be used to format numbers as you
described. For example:

Code:
DecimalFormat df = new DecimalFormat("#,##0;(#,##0)");
System.out.println(df.format(70000000));

Reply With Quote
  #3  
Old October 30th, 2001, 08:59 AM
gappelman gappelman is offline
Balance is everything!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 44 gappelman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
It seems to make sense, but I dont quite understand how to apply it to my code.

I would be most appreciative if you could elaborate a bit...

Thank's
Gerard

Reply With Quote
  #4  
Old October 30th, 2001, 10:13 AM
ehsiung ehsiung is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Pittsburgh, PA
Posts: 3 ehsiung User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Since you're posting in this forum I assume you're using JSP.
You'll have to replace your javascript with Java, here's an
example of how you can use DecimalFormat:

Code:
<%@ page import="java.text.DecimalFormat" %>
<html>
<%!
    public String pretty(long val)
    {
        DecimalFormat df = new DecimalFormat("#,##0;(#,##0)");
        return df.format(val);
    }
%>    
<body>

<%= pretty(70000000) %>

</body>
</html>

Reply With Quote
  #5  
Old October 30th, 2001, 10:37 AM
gappelman gappelman is offline
Balance is everything!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 44 gappelman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I keep my head in the trenches, and I don't look around me.

I am filled with humble sorrow!
I was in the wrong forum. I do not know the difference between JSP and JavaScript.

I am working with PHP, and I could only find a way to convert the numbers in JavaScript.

Do you perhapse have an equal solution for me in JavaScript

Thank's
Gerard

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Converting a number to decimal?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway