I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.
I want to convert this into text format (compass rose) with 16 di
Javascript function 100% working
function degToCompass(num) {
while( num < 0 ) num += 360 ;
while( num >= 360 ) num -= 360 ;
val= Math.round( (num -11.25 ) / 22.5 ) ;
arr=["N","NNE","NE","ENE","E","ESE", "SE",
"SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"] ;
return arr[ Math.abs(val) ] ;
}
steps
Hope it helps