paulorlowski
Programmer
I modified some code to create a running meter with integers which works in the code below.
$7,024,200
$7,024,201
$7,024,202
In the second example I want to add 2 decimal places, but I'm having problems. The number shifts left and right which creates an annoying flashing look and makes it hard to read. I'm also getting extra commas and extra 9's after the decimal: $7,024,200.,029999999
I'd appreciate some help.
Paul
<html>
<body>
<script Language="JavaScript">
<!--
//Display Energy Costs like a running meter or gauge on a gas pump.
//Integer display works great
var num;
function displayPumpReading() {
num = 7024200;
updatePumpReading();
}
function updatePumpReading() {
var intValue;
var displayValue;
var strValue;
var strLen;
intValue = Math.ceil(num + parseFloat(0.01));
strValue = intValue.toString();
strLen = strValue.length;
document.Energycost.local.size = strLen
displayValue = "";
for(i = strLen; i > 0; i -= 3) {
displayValue = "," + strValue.substring(i-3,i) + displayValue;
}
displayValue = "$ " + displayValue.substring(1,displayValue.length);
document.Energycost.local.value = displayValue;
num += 0.01;
setTimeout("updatePumpReading()","10"
}
// -->
<!--
// Display 2 decimals
// Get rid of commas and annoying flashing
var num;
function displayPumpReadingD() {
num = 7024200.00;
updatePumpReadingD();
}
function updatePumpReadingD() {
var intValue;
var displayValue;
var strValue;
var strLen;
// intValue = Math.ceil(num + parseFloat(0.01));
intValue = Math.abs(num + parseFloat(0.01));
strValue = intValue.toString();
strLen = strValue.length;
document.EnergycostD.local.size = strLen
displayValue = "";
for(i = strLen; i > 0; i -= 3) {
displayValue = "," + strValue.substring(i-3,i) + displayValue;
}
displayValue = "$ " + displayValue.substring(1,displayValue.length);
document.EnergycostD.local.value = displayValue;
num += 0.01;
setTimeout("updatePumpReadingD()","10"
}
// -->
</script>
Integer Gauge<form name="Energycost">
<input type="text" name="local" class="pumptextbox" style="width: 160px;" size="20"><p>
</form>
<script>
<!--
displayPumpReading();
//-->
</script>
Decimal Gauge:
<form name="EnergycostD">
<input type="text" name="local" class="pumptextbox" style="width: 160px;" size="20"><p>
</form>
<script>
<!--
displayPumpReadingD();
//-->
</script>
</body>
</html>
$7,024,200
$7,024,201
$7,024,202
In the second example I want to add 2 decimal places, but I'm having problems. The number shifts left and right which creates an annoying flashing look and makes it hard to read. I'm also getting extra commas and extra 9's after the decimal: $7,024,200.,029999999
I'd appreciate some help.
Paul
<html>
<body>
<script Language="JavaScript">
<!--
//Display Energy Costs like a running meter or gauge on a gas pump.
//Integer display works great
var num;
function displayPumpReading() {
num = 7024200;
updatePumpReading();
}
function updatePumpReading() {
var intValue;
var displayValue;
var strValue;
var strLen;
intValue = Math.ceil(num + parseFloat(0.01));
strValue = intValue.toString();
strLen = strValue.length;
document.Energycost.local.size = strLen
displayValue = "";
for(i = strLen; i > 0; i -= 3) {
displayValue = "," + strValue.substring(i-3,i) + displayValue;
}
displayValue = "$ " + displayValue.substring(1,displayValue.length);
document.Energycost.local.value = displayValue;
num += 0.01;
setTimeout("updatePumpReading()","10"
}
// -->
<!--
// Display 2 decimals
// Get rid of commas and annoying flashing
var num;
function displayPumpReadingD() {
num = 7024200.00;
updatePumpReadingD();
}
function updatePumpReadingD() {
var intValue;
var displayValue;
var strValue;
var strLen;
// intValue = Math.ceil(num + parseFloat(0.01));
intValue = Math.abs(num + parseFloat(0.01));
strValue = intValue.toString();
strLen = strValue.length;
document.EnergycostD.local.size = strLen
displayValue = "";
for(i = strLen; i > 0; i -= 3) {
displayValue = "," + strValue.substring(i-3,i) + displayValue;
}
displayValue = "$ " + displayValue.substring(1,displayValue.length);
document.EnergycostD.local.value = displayValue;
num += 0.01;
setTimeout("updatePumpReadingD()","10"
}
// -->
</script>
Integer Gauge<form name="Energycost">
<input type="text" name="local" class="pumptextbox" style="width: 160px;" size="20"><p>
</form>
<script>
<!--
displayPumpReading();
//-->
</script>
Decimal Gauge:
<form name="EnergycostD">
<input type="text" name="local" class="pumptextbox" style="width: 160px;" size="20"><p>
</form>
<script>
<!--
displayPumpReadingD();
//-->
</script>
</body>
</html>