...

View Full Version : How to show the change in a number



Big
01-28-2008, 05:11 PM
I would like to know the javascript of how to show a change in a number.
Example:

Today

Ranked 786

Tommorow

Ranked 779 -7

How do I make it so that Javascript will change that for me by showing that the number has changed by -7 so I won't have to do it manually?

jaywhy13
01-28-2008, 05:17 PM
Not exactly sure what you wanna do. But uhhhh I think "eval" might help you.

alert(eval("700 - 5")); // will alert 695

Possibly you could store the decrement in one value and the actual value in another.
So you could probably do something like...

var total = 700;
var decrement = 5;
eval(total + " - " + decrement); // forms the string "700 - 5" , hence givin 695

Big
01-28-2008, 05:20 PM
Well i want this page to show rankings and if a ranking is 787 but the next day its 779 i want the javascript to show the change (in this case -8) next to the ranking automatically.

Ranking 779 -8

jaywhy13
01-28-2008, 05:37 PM
Well i want this page to show rankings and if a ranking is 787 but the next day its 779 i want the javascript to show the change (in this case -8) next to the ranking automatically.

Ranking 779 -8

Not sure if you even need to use eval.

var todayRating = 779;
var yesterdayRating = 787;
var ratingDifference = ("Today\'s rating is: " + todayRating + " " + (todayRating - yesterdayRating);
alert(ratingDifference); // Will prompt: "Today's rating is 779 - 8"

Big
01-28-2008, 05:55 PM
didn't work
thanks anyway though

Philip M
01-28-2008, 06:43 PM
var todayRating = 779;
var yesterdayRating = 787;
var ratingDifference = ("Today\'s rating is: " + todayRating + " = a change of " + (todayRating - yesterdayRating) ) ; // missing bracket
alert(ratingDifference); // Will prompt: "Today's rating is 779 - 8



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum