#1
  1. No Profile Picture
    Balance is everything!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    44
    Rep Power
    14

    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
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Pittsburgh, PA
    Posts
    3
    Rep 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));
  4. #3
  5. No Profile Picture
    Balance is everything!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    44
    Rep Power
    14
    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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Pittsburgh, PA
    Posts
    3
    Rep 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>
  8. #5
  9. No Profile Picture
    Balance is everything!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    44
    Rep Power
    14
    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

IMN logo majestic logo threadwatch logo seochat tools logo