Ask Experts Questions for FREE Help !
Ask
    banjax's Avatar
    banjax Posts: 9, Reputation: 2
    New Member
     
    #1

    Jun 22, 2009, 06:20 AM
    How to optimise output for a thousandth breakdown (for currency)?
    Hello there,

    I am having bother with fixing an output of some data calculations I have into thousandths. I require the output to place a comma where a thousandth is formed, so it's an easier read currency. I also have these fields set to 2 decimal places though, so I wonder if there is anyway to include this in the script?

    As you can see from this code below, I have used the .toFixed(-) code, therefore I require a method to break down the thousandths in the same way.

    Code:
    <script language="JavaScript">
    
    function showpay() {
     if ((document.calc.a.value == null || document.calc.a.value.length == 0) ||
         (document.calc.b.value == null || document.calc.b.length == 0) ||
         (document.calc.c.value == null || document.calc.c.value.length == 0) ||
         (document.calc.d.value == null || document.calc.d.value.length == 0) ||
         (document.calc.e.value == null || document.calc.e.value.length == 0))
    	  
     { alert("Please enter all values");
     }
     else
     {
     var aa = document.calc.a.value;
     var ab = document.calc.b.value;
     var ac = document.calc.c.value;
     var ad = document.calc.d.value;
     var ae = document.calc.e.value;
    
     var af = document.calc.f.value;
     var ag = document.calc.g.value;
     var ah = document.calc.h.value;
      
     var ai = document.calc.i.value;
     var aj = document.calc.j.value;
     var ak = document.calc.k.value;
    
     var al = document.calc.l.value;
     var am = document.calc.m.value;
     var an = document.calc.n.value;
     var ao = document.calc.o.value;
     
     var ap = document.calc.p.value;
     var aq = document.calc.q.value;
     var ar = document.calc.r.value;
     var as = document.calc.s.value;
     
     var at = document.calc.t.value;
     var au = document.calc.u.value;
     var av = document.calc.v.value;
     var aw = document.calc.w.value;
    
    // calculations
    
     document.calc.f.value = ab * ac;
     document.calc.g.value = ((ac * ad).toFixed( 2 ));
     document.calc.h.value = ((ae / ag).toFixed( 2 ));
     
     document.calc.i.value = ((ah / 4.3).toFixed( 2 ));
     document.calc.j.value = ((ai / 4.3).toFixed( 2 ));
     document.calc.k.value = ((ah / 52).toFixed( 2 ));
     
     document.calc.l.value = aa * 1;
     document.calc.m.value = ("$" +(aa * af).toFixed( 2 ));
     document.calc.n.value = ad * af;
     document.calc.o.value = ("$" +(aa * ag).toFixed( 2 ));
     
     document.calc.p.value = aa * 4.3;
     document.calc.q.value = ("$" +(af * ap).toFixed( 2 )); 
     document.calc.r.value = ad * ap;
     document.calc.s.value = ("$" +(ag * ap).toFixed( 2 ));
     
     document.calc.t.value = ap * 12; 
     document.calc.u.value = ("$" +(af * at).toFixed( 2 ));
     document.calc.v.value = ad * at;
     document.calc.w.value = ("$" +(ag * at).toFixed( 2 ));
    
     }
    }
    
    </script>
    Many thanks in advance.

    DS
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Jun 22, 2009, 07:34 AM
    There is a NumberFormat.getInstance(Locale.______); function that will format numbers. You'll probably have to assign the value to a string and then print the string rather than trying to incorporate it all onto one line.

    Formatting Numbers in Java

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Mental Breakdown? [ 5 Answers ]

Well Im pretty sure I know the answer but I feel like Im about to break down. I have dealt with depression and other Psychotic Disorders from the age of 13yrs old. Im 28 yrs now. I felt like that I didn't have a problem. At the time I was a Santanist and that the problems where stemming form...

I am near a psychological breakdown... [ 8 Answers ]

I had a girl friend two days ago... Any thing she or her family asked for I gave... I mean for exactly 2 years I took them out when her father got paralized I gave my car I took them out to dinner lunch... every day what ever she asked for I bought for her I spent exactly 53,000 euros on...

Am I going to have a breakdown? [ 1 Answers ]

Ok, lets see... Lets start with my father. 18 years ago he was arrested for the rape of a 15 year old girl. ( The truth is it was consensual, not right, but not rape ) Just last year he was informed he had to register as a sex offender, which he did, even though he isn't! In February he was...


View more questions Search