0

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;
};

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your comment. I tried that already, and unfortunately didn't work. The ≈ character doesn't display correctly in Notepad++, and in the browser a �-sign appears.
Then you need to ensure that the encoding Notepad++ to save as and the encoding the server is configured to claim the document is using (in the Content-Type header) are both UTF-8.
Ah yes, works like a charm, thank you! The problem was that I was coding in ANSI. I went to menu Format -> Convert to UTF-8 (without BOM). Using the JavaScript unicode escape sequence (\u2248) worked even when coding in ANSI.
0

You can try with:

 return '≈' + numRounded;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.