Home › Forums › JavaScript › Increment counter formatting
- This topic is empty.
-
AuthorPosts
-
December 1, 2012 at 5:09 pm #41100
i3a1l3y
MemberBasically the counter I have created for a website seems to be working as I want it to (I can edit it to do what I want) – but for some reason when I increment it by decimals i.e. 0.1, 0.2, 0.3 etc the formatting glitches?
You can view the counter live at http://lowco2.eu
Here is the code behind the counter:
Script:
>
var number = =(int)((time()-1262325600)/150);?>; // put your initial value here
function incrementNumber () {
number += 0.1; // you can increment by anything you like here
document.getElementById('total').innerHTML = number;
}// this will run incrementNumber() every second (interval is in ms)
setInterval(incrementNumber, 1000);function formatNumber(num) {
num = String(num);if (num.length <= 3) {
return num;
} else {
var last3nums = num.substring(num.length - 3, num.length);
var remindingPart = num.substring(0, num.length - 3);
return formatNumber(remindingPart) + ',' + last3nums;
}
}Any help is much appreciated!
December 5, 2012 at 6:58 am #116369i3a1l3y
MemberCan anyone help with this at all?
Cheers
December 5, 2012 at 7:09 am #116370Paulie_D
MemberI’m not seeing a counter on the link you provided.
EDIT: Wow that’s hard to see.
December 5, 2012 at 7:14 am #116371Watson90
MemberI don’t see the point behind having it on your website anyway as it’s not really a true reflection on the amount you’re exactly saving to be honest…
But i just ran your code through [JSLint](http://www.jslint.com/ “”) on the JSFiddle website and it threw back a few errors.
Try changing this;
var number = =(int)((time()-1262325600)/150);?>;
To this;
var number = (int)((time()-1262325600)/150);
This is what I got – Here
December 6, 2012 at 5:40 pm #116556i3a1l3y
Member> I’m not seeing a counter on the link you provided.
EDIT: Wow that’s hard to see.
It isn’t live hence it being hard to see, but thanks for your lack of help!
Thanks Watson… I will give it a try and see if it begins to sort it out.
It is possible to work out an estimate by taking the average tonnes of co2 they save over the last 3 years. I only design what they want though, so I won’t defend the need of it!
Cheers
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.