Merge pull request #471 from duckduckgo/jag/precision

Conversions: Only switch to exponent format after 1000000
master
Rob Emery 2014-06-04 21:26:50 +01:00
commit 980c03f570
2 changed files with 10 additions and 4 deletions

View File

@ -109,7 +109,13 @@ handle query_lc => sub {
$result = $c->convert( { 'factor' => $factor, 'from_unit' => $matches[0], 'to_unit' => $matches[1], 'precision' => $precision, } );
}
$f_result = (sprintf "%.${precision}g", $result->{'result'});
# We only display it in exponent form if it's above a certain number.
# We also want to display numbers from 0 to 1 in exponent form.
if($result->{'result'} > 1000000 || $result->{'result'} < 1) {
$f_result = (sprintf "%.${precision}g", $result->{'result'});
} else {
$f_result = (sprintf "%.${precision}f", $result->{'result'});
}
}
# handle pluralisation of units

View File

@ -16,13 +16,13 @@ ddg_goodie_test(
'convert 0.111 stone to pound' => test_zci('0.111 stone is 1.554 pounds',),
'3 kilogramme to pound' => test_zci('3 kilograms is 6.614 pounds',),
'1.3 tonnes to ton' => test_zci('1.3 metric tons is 1.433 tons',),
'2 tons to kg' => test_zci('2 tons is 1.81e+03 kilograms',),
'2 tons to kg' => test_zci('2 tons is 1814.372 kilograms',),
'1 ton to kilos' => test_zci('1 ton is 907.186 kilograms',),
'3.9 oz in g' => test_zci('3.9 ounces is 110.563 grams',),
'2 miles to km' => test_zci('2 miles is 3.219 kilometers',),
'convert 5 feet to in' => test_zci('5 feet is 60 inches',),
'0.5 nautical mile to klick' => test_zci('0.5 nautical miles is 0.926 kilometers',),
'500 miles in metres' => test_zci('500 miles is 8.05e+05 meters',),
'500 miles in metres' => test_zci('500 miles is 804672.249 meters',),
'25 cm in inches' => test_zci('25 centimeters is 9.843 inches',),
'1760 yards to miles' => test_zci('1760 yards is 1 mile',),
'3520yards to miles' => test_zci('3520 yards is 2 miles',),
@ -40,7 +40,7 @@ ddg_goodie_test(
'convert 25 inches into feet' => test_zci('25 inches is 2.083 feet'),
'42 kilowatt hours in joules' => test_zci('42 kilowatt-hours is 1.51e+08 joules'),
'2500kcal in tons of tnt' => test_zci('2500 large calories is 0.003 tons of TNT'),
'90 ps in watts' => test_zci('90 metric horsepower is 6.62e+04 watts'),
'90 ps in watts' => test_zci('90 metric horsepower is 66194.888 watts'),
'1 gigawatt in horsepower' => test_zci('1 gigawatt is 1.34e+06 horsepower'),
'180 degrees in radians' => test_zci('180 degrees is 3.142 radians'),
'270 degrees in quadrants' => test_zci('270 degrees is 3 quadrants'),