Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  View Answers    Answer this question    Ask a question  
 

banjax
Jun 22, 2009, 06:20 AM
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.

<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
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 (http://www.iro.umontreal.ca/~vaucher/Java/tutorials/Formatting.html)