在javascript中以度数显示风向

问题描述 投票:0回答:1

如何在javascript中以90度显示风向(包括在数字后使用小圆圈度符号)?

我只能在文字说明中显示-以下代码。

谢谢。

function text(d) {
        let directions = ['Northerly', 'North Easterly', 'Easterly', 'South Easterly', 'Southerly', 'South Westerly', 'Westerly', 'North Westerly'];

        d += 22.5;

        if (d < 0)
            d = 360 - Math.abs(d) % 360;
        else
            d = d % 360;

        let w = parseInt(d / 45);
        return `${directions[w]}`;
    }
javascript jquery weather weather-api
1个回答
0
投票

非常容易:

function text(d) {
        let directions = ['Northerly', 'North Easterly', 'Easterly', 'South Easterly', 'Southerly', 'South Westerly', 'Westerly', 'North Westerly'];

        d += 22.5;

        if (d < 0)
            d = 360 - Math.abs(degree) % 360;
        else
            d = d % 360;

        let w = parseInt(d / 45);
        return `${directions[w]}`;
    }

    deg = 67;

    console.log(deg + String.fromCharCode(0xfeff00b0) + ' = ' + text(deg));
© www.soinside.com 2019 - 2024. All rights reserved.