|
Post by Chris/Colonie, NY on Nov 30, 2003 17:00:11 GMT -5
I was wondering if anyone knew if there was an easy way to round off the values to what they are on the VP console. For example....39.5 degrees on WeatherLink software could be rounded up to 40 degrees on my web site as it is on the console. Same with dewpoint...wind chill..heat index etc.
Thanks,
Chris
|
|
|
Post by Admin on Dec 1, 2003 9:44:02 GMT -5
Well, the console can display in tenths, too, if you wish, but to round off the numbers on your web site, Javascript is probably the easiest. An example follows:
<script language="javascript"> temp = Math.round(<!--outsideTemp--> ) document.write(temp) </script>
I do this for wind speed; using MPH the wind speed only has resolution to one MPH, so seeing 4.0 mph, 23.0 mph, etc. is a little silly.
|
|
|
Post by Chris/Colonie, NY on Dec 1, 2003 12:18:51 GMT -5
I tried using the code you gave me, but it didn't work for some reason. The actual code at one point showed in the table were I placed it and then I re-entered it and the code in html turned red. I'm am using Microsoft Front Page 2000....I'm not sure what the problem is.
Chris
|
|
|
Post by Admin on Dec 1, 2003 13:43:21 GMT -5
Try this slight variation - and make sure you use the tag for outside temperature or whatever you're interested in. I'm guessing at the tag, it might be <!--outsideTemperature--> rather than <!--outsideTemp-->.
<script language="JavaScript"> var temp = Math.round(<!--outsideTemp-->) document.write(temp) </script>
|
|
|
Post by Chris/Colonie, NY on Dec 1, 2003 15:21:11 GMT -5
Gary,
The code doesn't work.....it still shows up in the table where I placed it, word for word. The temp. appears in the parenthesis but is not rounded.
Chris
|
|
|
Post by Admin on Dec 1, 2003 16:42:39 GMT -5
Chris, I tested the code; it does work as presented. Perhaps you need to enable Javascript on your browser.
Make sure that the outside temp tag in the javascript has parentheses before and after it (the forum changes the greater than + right paren into a smiley).
|
|
|
Post by Chris/Colonie, NY on Dec 2, 2003 16:58:47 GMT -5
Gary:
Just letting you know that it works. I thank you for helping me. One more question....now for the other values I want rounded such as wind...barometic pressure......heat index...wind chill etc, I would use the same code but sub in the weather tag?
Thanks again, Chris
|
|
|
Post by Chris/Colonie, NY on Dec 2, 2003 19:59:10 GMT -5
Gary: I figured it out. I'd thought I'd try fooling with it and I guess I did it correctly. Again...I thank you very much for helping me with this. Chris www.geocities.com/colonieweather
|
|
|
Post by Admin on Dec 3, 2003 8:05:34 GMT -5
Sure thing, Chris. Did you get my e-mail in response to the template you'd sent me? Hopefully removing the <!--tempUnit--> tag took care of it.
|
|
|
Post by Chris/Colonie, NY on Dec 3, 2003 8:13:11 GMT -5
Gary,
Yea I got your email. I thinks thats wht did it plus putting one line of the code under the other help too.
Thanks again,
Chris
|
|
|
Post by gclarkso on May 26, 2005 10:29:04 GMT -5
Well, the console can display in tenths, too, if you wish, but to round off the numbers on your web site, Javascript is probably the easiest. An example follows: <script language="javascript"> temp = Math.round(<!--outsideTemp--> ) document.write(temp) </script> I do this for wind speed; using MPH the wind speed only has resolution to one MPH, so seeing 4.0 mph, 23.0 mph, etc. is a little silly. The code that is posted works flawlessly for temp, dew point and windspeed however, I cannot figure out how to modify the script to leave 2 decimal places (in/Hg) for the barometric pressure value. Any takers? Thanks, Gordon
|
|
|
Post by xmas1313 on May 26, 2005 20:40:05 GMT -5
Hi Gordon!
I've got a way to do it which also uses JavaScript...
var baro=(Math.round(<!--barometer-->*100))/100;
Hope this helps,
Scott
|
|
|
Post by gclarkso on May 27, 2005 9:56:09 GMT -5
Hi Gordon! I've got a way to do it which also uses JavaScript... var baro=(Math.round(<!--barometer-->*100))/100; Hope this helps, Scott Scott, Thanks for your input but the supplied script modification resulted with a displayed whole number of 56 with my value of 29.628 in/Mb. I'm still pluggin' along though... Gordon
|
|
|
Post by xmas1313 on May 27, 2005 10:38:21 GMT -5
Gordon...
Works fine on my page. Make sure you're using the same variable name to write to the browser as is in the formula. Otherwise, I can't see why the value would have come out as 56 from 29.628.
Scott
|
|
|
Post by gclarkso on May 27, 2005 13:48:53 GMT -5
Gordon... Works fine on my page. Make sure you're using the same variable name to write to the browser as is in the formula. Otherwise, I can't see why the value would have come out as 56 from 29.628. Scott Looking at your page (from your profile) it seems all of the pressure values are out 3 decimal places (thousandths). Is it possible to post an example of the full script you use? Thanks, Gordon
|
|
|
Post by Admin on May 27, 2005 14:45:20 GMT -5
Somebody came up with a solution for this, I'm trying to dig it up somewhere.
|
|
|
Post by xmas1313 on May 27, 2005 23:34:58 GMT -5
Gordon...
This code is used to display the pressure in the left title cell (black box near the top of the page). All you should need is...
var baro=(Math.round(<!--barometer-->*100))/100;
Make sure it's inside your Javascript tags. Then, just reference it anywhere else as...
<script>document.write(baro)</script>
If you need to view my html source, feel free.
Scott
|
|
|
Post by gclarkso on May 31, 2005 9:21:11 GMT -5
Scott, Thanks for your reply...Looking at the source of a few pages that use Java it seems there are lines of code in the head section of the page that looks like a pre-requisite (for the lack of a better term) to use Java and Javascript. I don't use that method. I have a simple table that reports the current weather values and in my .htx file, whenever I reference my temp, dew point and windspeed tag, I have replaced it with the few lines of code that Gary had supplied earlier in this thread. Those couple lines round up the tenth place of the temp, dew point and windspeed to a whole number. I had hope there was a slight modification to that method to round up the thousandth place to hundredths on the pressure value. Feel free to take a look. centralmarylandweather.orgThanks, Gordon
|
|
|
Post by xmas1313 on May 31, 2005 12:47:52 GMT -5
Gordon,
I looked further into your html source, and I think I've found the reason it is not working. Instead of this...
<script language="javascript"> temp = (Math.round(<!--barometer-->*100))/100) document.write(temp) </script>
Try combining into one statement...
<script language="javascript"> document.write((Math.round(<!--barometer-->*100))/100) </script>
Also, make sure there are an equal number of left and right parentheses.
The only real difference in the way you are referencing these scripts and the way I am is that I have my declarations between <script> tags before the <body> section of my script, then reference the variable with document.write inside the body. You are doing both in the body of your html, within the same javascript tags. I think if you combine your declaration and reference into one line (as above) it will work.
If you do decide to move your variable declarations above the <body> in your html, make sure you give each variable a different name.
Scott
|
|
|
Post by gclarkso on May 31, 2005 16:17:05 GMT -5
Gordon, I looked further into your html source, and I think I've found the reason it is not working. Instead of this... <script language="javascript"> temp = (Math.round(<!--barometer-->*100))/100) document.write(temp) </script> Try combining into one statement... <script language="javascript"> document.write((Math.round(<!--barometer-->*100))/100) </script> Also, make sure there are an equal number of left and right parentheses. The only real difference in the way you are referencing these scripts and the way I am is that I have my declarations between <script> tags before the <body> section of my script, then reference the variable with document.write inside the body. You are doing both in the body of your html, within the same javascript tags. I think if you combine your declaration and reference into one line (as above) it will work. If you do decide to move your variable declarations above the <body> in your html, make sure you give each variable a different name. Scott Scott, BINGO! The modified script you supplied did the trick! Thanks for helping me figure this out...as well as your lesson in Javascript... Gordon
|
|