| Coding Forum Problems with your code? Let's hear about it. |
08-14-2005, 06:27 AM
|
#1 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
Processing Amount
I'm looking for a javascript that would start with a base of $250,000 and increase $1.67 every second. It is for a financial website that shows how much money they have processed. Anyone?
|
|
|
08-15-2005, 12:31 PM
|
#2 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
<Bump>
|
|
|
08-15-2005, 01:28 PM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
Thanks, but it is not a timer that I need.
|
|
|
08-15-2005, 01:30 PM
|
#5 (permalink)
|
|
v7n Mentor
Join Date: 11-01-04
Location: USA! USA! USA!
Posts: 2,851
Latest Blog: None
|
Yeah it is.
|
|
|
08-15-2005, 01:31 PM
|
#6 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
How?
|
|
|
08-15-2005, 01:46 PM
|
#7 (permalink)
|
|
v7n Mentor
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,940
|
You can do something like this. I just don't have the time to figure out the rounding and $$$ formatting.
Shouldn't be too hard or this should point you in the right direction. Sorry I can't do the rest right now. Maybe someone else can take it a step further!
It works you just get a number like (250005.01000000004).
<script type="text/javascript">
<!--
if (document.getElementById) {
document.write('<p id="timer">250000</p>');
setInterval("document.getElementById('timer').firs tChild.data = Number(document.getElementById('timer').firstChild .data) + 1.67", 1000);
}
// -->
</script>
imaginemn
|
|
|
08-15-2005, 01:51 PM
|
#8 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
Thanks, but the only problem is that it would not keep counting. It needs to start counting and keep counting, all the time.
|
|
|
08-15-2005, 03:41 PM
|
#9 (permalink)
|
|
Contributing Member
Join Date: 07-30-05
Posts: 284
Latest Blog: None
|
Js will work, but it will RESET whenever a page with this code on it is displayed.
Flash will work but with the SAME problem as JS.
You can get JS to work but, you will have to pick a date say 1/1/05 for the "starting" 250K. Then add X for each second AFTER it.
|
|
|
08-15-2005, 05:07 PM
|
#10 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
Code:
<script language = "javascript">
// PLACE THE START DATE IN THESE VARIABLES
// EXAMPLE: 1ST AUGUST 2005
var day = 1;
var month = 8;
var year = 2005
// START VALUE IN DOLLARS
var Start_Value = 250000;
// SECOND INCREMENT IN DOLLARS
var Increment = 1.67;
// EPOCH DATE
Then = new Date(0);
// DATE TO START COUNT
Increment_Start = new Date(year, month-1, day ,0 ,0, 0);
// AND THE DATE NOW
Now = new Date();
// MAKE UNIX TIMESTAMP FOR NOW
Millisecond_Timestamp = Now-Then;
Timestamp = Math.round(Millisecond_Timestamp/1000);
// MAKE UNIX TIMESTAMP FOR START OF COUNT
Millisecond_Timestamp = Increment_Start-Then;
Increment_Start_Timestamp = Math.round(Millisecond_Timestamp/1000);
// DIFFERENCE IN SECONDS FROM THE START OF THE COUNT UNTIL NOW
Difference = Timestamp - Increment_Start_Timestamp;
// DIFFERENCE IN SECONDS MULTIPLIED BY THE INCREMENT (ROUNDED)
Value_To_Add = Math.round(Difference * Increment);
// ECHO THE RESULT
document.write('Transactions processed since: ' + day + '/' + month + '/' + year +' = $');
document.write(Start_Value + Value_To_Add);
document.write('<br/>');
</script>
Last edited by jg_v7n : 08-15-2005 at 05:11 PM.
|
|
|
08-16-2005, 05:13 AM
|
#11 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
Thanks! It works perfectly!
|
|
|
08-16-2005, 05:56 AM
|
#12 (permalink)
|
|
v7n Mentor
Join Date: 08-26-04
Location: Rio de Janeiro
Posts: 1,289
Latest Blog: None
|
np
|
|
|
08-16-2005, 06:32 AM
|
#13 (permalink)
|
|
Contributing Member
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
Latest Blog: None
|
How can I add comas?
|
|
|
08-16-2005, 09:44 AM
|
#14 (permalink)
|
|
v7n Mentor
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,940
|
Add a format currency function to it.
Here is the modified code with it.
Code:
<script language = "javascript">
// PLACE THE START DATE IN THESE VARIABLES
// EXAMPLE: 1ST AUGUST 2005
var day = 1;
var month = 8;
var year = 2005
// START VALUE IN DOLLARS
var Start_Value = 250000;
// SECOND INCREMENT IN DOLLARS
var Increment = 1.67;
// EPOCH DATE
Then = new Date(0);
// DATE TO START COUNT
Increment_Start = new Date(year, month-1, day ,0 ,0, 0);
// AND THE DATE NOW
Now = new Date();
// MAKE UNIX TIMESTAMP FOR NOW
Millisecond_Timestamp = Now-Then;
Timestamp = Math.round(Millisecond_Timestamp/1000);
// MAKE UNIX TIMESTAMP FOR START OF COUNT
Millisecond_Timestamp = Increment_Start-Then;
Increment_Start_Timestamp = Math.round(Millisecond_Timestamp/1000);
// DIFFERENCE IN SECONDS FROM THE START OF THE COUNT UNTIL NOW
Difference = Timestamp - Increment_Start_Timestamp;
// DIFFERENCE IN SECONDS MULTIPLIED BY THE INCREMENT (ROUNDED)
Value_To_Add = Math.round(Difference * Increment);
// ECHO THE RESULT
document.write('Transactions processed since: ' + day + '/' + month + '/' + year +' = ');
document.write(formatCurrency(Start_Value + Value_To_Add));
document.write('<br/>');
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
</script>
imaginemn
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 04:27 AM.
© Copyright 2008 V7 Inc
|