Convert centimeters to inches

后端 未结 1 1876
逝去的感伤
逝去的感伤 2021-02-08 10:01

I need a JavaScript function to convert CM to IN. I have been using the following:

function toFeet(n) {
  var realFeet = ((n*0.393700) / 12);
  var feet = Math.f         


        
1条回答
  •  野的像风
    2021-02-08 10:47

    Your code is correct and gives the right result.

    I would change it in the following way, so I am sure I do not lose precision using an approximate number for the conversion. This may be useless in your case, but sometimes could come into play (e.g. calculating distances on maps).

    var realFeet = n / 30.48; // = 12 * 2.54
    

    0 讨论(0)
提交回复
热议问题