I am trying to include the degrees Celsius symbol (°C) in my code, this is what I have and it is not working:
$('#temp').unbind().append((Math.round(temperature - 273.15)) + '℃');
I am trying to include the degrees Celsius symbol (°C) in my code, this is what I have and it is not working:
$('#temp').unbind().append((Math.round(temperature - 273.15)) + '℃');
Share
Improve this question
asked Sep 12, 2015 at 20:58
Jon DanJon Dan
951 gold badge1 silver badge10 bronze badges
4
|
8 Answers
Reset to default 8You just miss ;
in ℃
An HTML entity has the format &name;
as pointed out already by Arsen.
Here is an alternative found here:
var temperature = 305;
$('#temp').unbind().append((Math.round(temperature - 273.15)) + '°');
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<div id="temp">Temperature in degrees Celsius is </div>
I simply copied the degrees symbol directly from the Character Editor in Windows.
Start --> symbols --> character map
Then select copy and paste it into your code ...
ctx.fillText(degrees.toFixed(2) +"º", x, y + 50);
Another approach is to utilize the in-built Int.NumberFormat
Javascript object:
const number = 100;
const degrees = new Intl.NumberFormat('en-US', {
style: 'unit',
unit: 'celsius',
});
console.log(degrees.format(number));
You can review the documentation here
use sup tag to place O it above a text.
e.g.
<p>31<sup>O</sup>C</p>
I realise that this question was asked six years and ten months ago but if anyone stumbles upon this looking for what I was, I found the following to be helpful.
Use the JavaScript method codePointAt()
to retrieve the code point integer from the symbol:
let unicodeDegCel = '℃'.codePointAt(0);
This will return the integer 8451. Now use the JavaScript method fromCodePoint()
prepended with String
, using the character code retrieved from codePointAt()
:
let degreesCelcius = String.fromCodePoint(8451);
This is was what eventually enabled me to use the degrees celcius symbol in ChartJS.
Source: Convert a character to its ASCII code in JavaScript
The hexadecimal code "\xB0"
generates that Celsius/Fahrenheit sign. :)
var degfahren = prompt("suggest a number" , 50);
var degcelc = (degfahren - 32) * 5\9;
console.log(degfahren+"\xB0 deg Fahrenheit "+"is eqaul to the "+degcelc+"\xB0 celcius");
To get the celsius symbol, this will work as of 2024: "\u2103"
°C
– Kristijan Iliev Commented Sep 12, 2015 at 21:00℃
try℃
(tested and working) – CollinD Commented Sep 12, 2015 at 21:01'°C'
? – Bergi Commented Sep 12, 2015 at 21:14