title: Convert cm to km, meters and cm
body: <p>I'm trying to do an activity where I need do put a number in cm, and the program has to return it with km, m, and cm.</p>
  
  <p><strong>An example:</strong> 270004 cm = 2km, 700m, 4cm // 100cm = 0km, 1m, 0cm.</p>
  
  <p>I have done this code, but, sometimes I get negative numbers, and sometimes I get strange numbers.</p>
  
  <p>Maybe is why I use the <code>PHP_ROUND_HALF_UP</code>??</p>
  
  <p>What can I do to solve it?</p>
  
  <pre><code>//I have an HTML form to introduce the number value
  $num = 123456789;
  
  $km = $num/1000;
  $km = round($km, 0, PHP_ROUND_HALF_UP);
  echo "km: ".$km."&lt;br&gt;";
  
  $subtraction = ($km * 1000) - $num;
  $m = $subtraction / 100;
  $m = round($m, 0, PHP_ROUND_HALF_UP);
  
  echo "m: ".$m."&lt;br&gt;";
  
  $subtraction2 = ($m * 100) - $subtraction;
  $cm = $subtraction2;
  
  echo "cm: ".$cm."&lt;br&gt;";           
  </code></pre>