...

View Full Version : Need help with Split function



Sawred
05-07-2007, 08:43 PM
Okay this is the entire program and it's working EXCEPT I would like to do a split function for lifesaved variable. Right now the answer is something like 19.734566 I want the .734566 portion everytime so I can multiply by 24 and take that answer and get the .323223 and multiply by min. Unfortuantly everytime I make a change to this thing I lose my output. Please help thanks:thumbsup:



<HTML>
<HEAD>
<TITLE>Time since my last smoke</TITLE>
</HEAD>
<BODY BGCOLOR="#F0E68C" >
<H4><CENTER>Time since I last smoked</H4>

<BODY>

<SCRIPT type="text/javascript">


function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTUP SCRIPT HERE//////////////////

//STEP 1: Configure the date to count up from, in the format year, month, day:
//This date should be less than today
setcountup(2007,1,2)

//STEP 2: Configure text to be attached to count up
var displaymessage="have passed since my last cigarette!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countup area
var countupwidth='800px'
var countupheight='35px'
var countupbgcolor=''
var opentags='<font face="Verdana" color="black"><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
var dropret='<br>'



function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)

document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')



window.onload=start_countup


function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

var cigpackcost='4.15'
var dollaramt=(dday*cigpackcost)
var dollarsign="$"
var sincei=" Amount of money I've said since I quit smoking"
var numofcigs='20'
var parta=(dday*numofcigs)
var partz=(numofcigs/24)
var partb=(dhour*partz)
var totalnumofsmokes=(parta+partb)
var saying=" Number of cigarettes not smoked"
var myquitdate="Matthew's quit date 1/2/2007 around 1 am"
var min_saved='11'
var lifesaved=((totalnumofsmokes*min_saved)/1440)
var mylifeback=" days of my life saved"
var length='3.75'
var distance=((totalnumofsmokes*length)/12)
var dang=" feet, if you took all the cigarettes I didn't smoke and laid them end to end that's how long it would be!"
var footballfield=(distance/300)
var wowzers=" number of football fields, with cigarettes laid end to end, thats just since I quit!"
var empire='1454'
var empirecalc=((distance/empire)*100)
var empirewow="% of the height of the Empire State Building, that's to the tip"
var ggate='8981'
var gglen=((distance/ggate)*100)
var gglenwow="% of the length of the Golden Gate"
var mgtar='8'
var oz='0.0352739619'
var oztartotal=(((totalnumofsmokes*mgtar)*oz)/1000)
var tar=(" Ounces, yes OUNCES of tar not put in my lungs")
var co='10.2'
var cototal=(((totalnumofsmokes*co)*oz)/1000)
var cotalk=(" Ounces of Carbon Monoxide, CO, not put in my lungs")
var cart=(dday/10)
var carttext=(" The numbers of cartons")
var est=(totalnumofsmokes/80300)*100
var esttext=("% Estimated percentage of not smoked to smoked")
var plane="2776"
var meandplane=((totalnumofsmokes*length)/plane)
var pl=" how many Boeing 747s I am long now"
var ls=lifesaved


if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+
displaymessage+dropret+totalnumofsmokes.toFixed(0)+saying+dropret+dollarsign+dollaramt.toFixed(2)+si ncei+
dropret+parseInt(lifesaved)+mylifeback+dropret+distance.toFixed(0)+dang+dropret+footballfield.toFixe d(1)+
wowzers+dropret+empirecalc.toFixed(2)+empirewow+dropret+gglen.toFixed(2)+gglenwow+dropret+meandplane .toFixed(2)+pl+dropret+
oztartotal.toFixed(2)+tar+dropret+cototal.toFixed(2)+cotalk+dropret+cart.toFixed(0)+carttext+dropret +est.toFixed(2)+
esttext+dropret+myquitdate+closetags+dropret+ls

setTimeout("countup()",1000)


}
</SCRIPT>



<p>
<font face="arial, helvetica" size="-2">Check out my blog<br>
<a href="http://sawredsublime.blogspot.com">Matthew</a></font>
<p>



</BODY>
</HTML>

glenngv
05-07-2007, 09:05 PM
Try this.

var lifesaved=((totalnumofsmokes*min_saved)/1440);
var decimalPortion = lifesaved - Math.floor(lifesaved);
alert(decimalPortion);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum