millimeters to feet/inches

筅森魡賤 提交于 2019-12-13 21:46:34

问题


I was wondering if anyone could help me create a function that will turn millimeters into feet/inches.

Example: 5280mm will be returned as 17ft / 3.87inches (or 17'3")

I know that there's 304.8mm in a foot, which gives me 17.322834645669 (using the same example above) but I'm not sure how to then format it into something more legible.

function getMeasurements($mm) { 
    return ($mm/304.8); 
}

回答1:


And if anyone is looking to do the same thing, this is what I used to calculate mm to ft/inches:

function getMeasurements($mm) {

    $inches = ceil($mm/25.4);
    $feet = floor(($inches/12));
    $measurement = $feet."'".($inches%12).'"';

    return $measurement;
}

Which returns something like: 17'3".




回答2:


If all you want to do is format the number, use number_format



来源:https://stackoverflow.com/questions/6906801/millimeters-to-feet-inches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!