|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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));
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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>
|
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Converting a number to decimal? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|