This is my javascript object and code
buildingJson: {
name: "build",
height: 40
}
var val = parseFloat(buildingJson.height).toFixed(2);
buildingJson.height = val;
console.log(typeof buildingJson.height);
This is always logging out a string even though the value is 40.0.
How to set the height to a floating point number in the buildingJson object.
buildingJson, even if it would be correct thenbuildingJsonis a JavaScript Object, and not JSON. JSON is a textual representation. And it becomes a string because oftoFixedMDN: Number.prototype.toFixed():[...]Returns: A string representation of numObj that does not use exponential notation and has exactly digits digits after the decimal place.[...]