Marcus Edensky
Marcus Edensky

Reputation: 944

Return special characters in html correctly from JavaScript

I have an angular function that returns rounded numbers. If the number was rounded, it will add the "almost equal to" sign (≈) in front of the returned number. The problem is, it's not displayed as a html character, but as the characters ≈ instead. How is this fixed?

$scope.roundAprox = function(num) { //Returns almost equal to before rounded number if number was rounded
    var numRounded = Math.round(num);
    if (numRounded != num) //Has been rounded
        return '≈' + numRounded;
    else //Has not been rounded
        return numRounded;
};

Upvotes: 0

Views: 281

Answers (2)

Elka
Elka

Reputation: 237

You can try with:

 return '≈' + numRounded;

Upvotes: 0

Quentin
Quentin

Reputation: 944564

Use the character itself (instead of an HTML entity in a context that doesn't expect HTML).

Alternatively, use a JavaScript unicode escape sequence (\u2248).

Upvotes: 2

Related Questions