Dan,captzero wrote:Hi Guys,
I need some help with some conversions & calculations and the <span> tags.
Previously, I was running some js to convert and display wind speed km/h to knots (for fishing buddies) easily enough. The old script was:
<script type="text/javascript">
var speed = "<#wlatest>";
var speedknots = Math.abs(speed*0.54*10)/10;
document.write(speedknots.toFixed(1));
</script> kts
I have been able to get the do a similar thing using the realtimereader.js by using:
var spknots = rawdata[6];
$("#speedknots").html(Math.abs(spknots*0.54*10)/10);
and the span tag is <span id="speedknots"></span>
However, this will give 1.6 km/h as 0.8640000000000001 knots.
How am I able to display with 1 decimal point, ie, as 0.8 knots. Am I close or way off the mark here?
I have tried several variants but it usually breaks the javascript.
Thanks in advance.
Based on the script you quoted above that worked, try this in the realtimereader.js
Code: Select all
var spknots = rawdata[6];
var speedknots = Math.abs(spknots*0.54*10)/10;
var speedknots = speedknots.toFixed(1);
$("#speedknots").html(speedknots);
The <span id="speedknots"></span> stays the same in your HTML.