By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Convert Meters to Kilometres

+3 votes

You will be given an integer that will be distance in meters. Write a program that converts meters to kilometers formatted to the second decimal point.


convert meters to kilometres php task

asked in PHP category by user Jolie Ann

1 Answer

+2 votes

My solution:


$inputMeters = intval(readline());
$kilometers = $inputMeters / 1000;

echo number_format($kilometers, 2, '.', '');

Use number_format (string function) /line 6 to format the kilometers to the second decimal point.

answered by user nikole