Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert 00B0 (degree sign) unicode character?

I have string 00B0 which is Unicode of degree sign how can I convert in to symbol?

var str = "00B0";
var degreeSign = convesion(str);
console.log(degreeSign);

How it possible ?

like image 572
Paresh Thummar Avatar asked Apr 11 '12 11:04

Paresh Thummar


People also ask

How do I type the degree symbol in Unicode?

For the degree symbol, this is done by entering Ctrl + ⇧ Shift + U B 0 (where the last key is the number zero) followed by a space. For ChromeOS, use the Unicode entry method Ctrl + ⇧ Shift + U then 0 0 B 0 then space or return; with the UK extended layout, use AltGr + ⇧ Shift + 0 .

What is the Alt code for degrees?

Insert the degree symbol by using a keyboard shortcut On your keyboard, press Alt + 0176. Note: This method works only for keyboards that include a 10-key numeric pad.

How do I make a degree symbol in string?

Use the string literal: \u00B0 . For Unicode characters, it will always be "\u" followed by the character code.


2 Answers

console.log('\u00B0');​​​​​​ // outputs ° in my chrome console

so basically: '\u00B0'

like image 76
Gert Van de Ven Avatar answered Oct 03 '22 17:10

Gert Van de Ven


Parse the string into a number to get the character code, then use the String.fromCharCode method to create a string from it:

var degreeSign = String.fromCharCode(parseInt(str, 16));
like image 30
Guffa Avatar answered Oct 03 '22 15:10

Guffa