Template talk:Convert

Latest comment: 12 years ago by Josh Parris in topic per is not a basic word

76 inches should be 193 cm

change

These are giving wrong output:

  • {{convert|6|ft|4|in|m|abbr=on}} => 6 ft 4 in (1.93 m)
  • {{convert|6|ft|4|in|cm|abbr=on}} => 6 ft 4 in (193 cm)
  • {{convert|76|in|cm|abbr=on}} => 76 in (190 cm)

They should convert to 1.93 m 193 cm 193 cm -- and do on "regular" wikipedia--JimWae (talk) 08:00, 2 July 2010 (UTC)Reply

  • Yes, the correct amounts should be 1.93 m & 193 cm: Sorry for waiting over a year, but the fix is to round by 1 extra digit if the amount is a whole integer (such as "76" rather than "76.6"). The fixed markup is in the sandbox version, Template:Convert/cm/sandbox. A similar fix was made to local Template:Convert/ft on 9 March 2010 (this edit: diff-338) to set precision "j" = {{#ifexpr: floor({{{1|9}}}) = ({{{1|9}}}) |-0-{{{j|0}}}|-0.515985037-{{{j|0}}} }}. That fix uses "floor({{{1}}})" to detect a whole (integer) amount and then sets j to round with 1 more digit in the result. This general problem was discussed for months on English Wikipedia, but of course, it takes a year to get changes over to Simple WP. -Wikid77 (talk) 13:10, 18 January 2012 (UTC)Reply
  • I doubt it makes a difference what page it is on - it is apparently NOT EVER calculating right. They should all convert to 1.93 m or 193 cm, but they are not. They are OK on "regular" wikipedia - and the code appears to be the same - so it must be one of the include pages on simple wp. Quite possibly it is multiplying by 2.5 rather than 2.54 -- as multiplying 76 x 2.5 = 190 and 76 x 2.54 = 193. However, 0.0254 does appear in Template:Convert/in - so maybe it is rounding too soon (?!? or maybe not)
  • Also:Template:Convert/and/in seems to have a syntax error --JimWae (talk) 05:40, 3 July 2010 (UTC)Reply

More cases of inches and cm

change

This should help:

  • {{convert|60|in|cm|abbr=on}} => 60 in (150 cm) -- should be 152, would be 150 if multiplied by 2.5
  • {{convert|70|in|cm|abbr=on}} => 70 in (180 cm) -- should be 178, would be 175 if multiplied by 2.5
  • {{convert|74|in|cm|abbr=on}} => 74 in (190 cm) -- should be 188
  • {{convert|75|in|cm|abbr=on}} => 75 in (190 cm) -- should be 191
  • {{convert|76|in|cm|abbr=on}} => 76 in (190 cm) -- should be 193
  • {{convert|77|in|cm|abbr=on}} => 77 in (200 cm) -- should be 196
  • {{convert|78|in|cm|abbr=on}} => 78 in (200 cm) -- should be 198


  • {{convert|720|in|cm|abbr=on}} => 720 in (1,800 cm) -- should be 1829
  • {{convert|730|in|cm|abbr=on}} => 730 in (1,900 cm) -- should be 1854
  • {{convert|740|in|cm|abbr=on}} => 740 in (1,900 cm) -- should be 1880

...

  • {{convert|749|in|cm|abbr=on}} => 749 in (1,900 cm) -- should be 1902
  • {{convert|750|in|cm|abbr=on}} => 750 in (1,900 cm) -- should be 1905
  • {{convert|751|in|cm|abbr=on}} => 751 in (1,910 cm) -- should be 1908
  • {{convert|752|in|cm|abbr=on}} => 752 in (1,910 cm) -- should be 1910
  • {{convert|753|in|cm|abbr=on}} => 753 in (1,910 cm) -- should be 1913
  • {{convert|754|in|cm|abbr=on}} => 754 in (1,920 cm) -- should be 1915
  • {{convert|755|in|cm|abbr=on}} => 755 in (1,920 cm) -- should be 1918
  • {{convert|756|in|cm|abbr=on}} => 756 in (1,920 cm) -- should be 1920
  • {{convert|757|in|cm|abbr=on}} => 757 in (1,920 cm) -- should be 1923
  • {{convert|758|in|cm|abbr=on}} => 758 in (1,930 cm) -- should be 1925
  • {{convert|759|in|cm|abbr=on}} => 759 in (1,930 cm) -- should be 1928
  • {{convert|760|in|cm|abbr=on}} => 760 in (1,900 cm) -- should be 1930
  • {{convert|761|in|cm|abbr=on}} => 761 in (1,930 cm) -- should be 1933
  • {{convert|762|in|cm|abbr=on}} => 762 in (1,940 cm) -- should be 1935
  • {{convert|763|in|cm|abbr=on}} => 763 in (1,940 cm) -- should be 1938
  • {{convert|764|in|cm|abbr=on}} => 764 in (1,940 cm) -- should be 1941
  • {{convert|765|in|cm|abbr=on}} => 765 in (1,940 cm) -- should be 1943


- appears to be rounding too soon -- STRANGELY, it converts 751 to a greater value than 760 --JimWae (talk) 09:30, 4 July 2010 (UTC)Reply

-IT IS taking the sig figs too literally:

  • {{convert|758.0|in|cm|abbr=on}} => 758.0 in (1,925 cm) -- should be 1925
  • {{convert|759.0|in|cm|abbr=on}} => 759.0 in (1,928 cm) -- should be 1928
  • {{convert|760.0|in|cm|abbr=on}} => 760.0 in (1,930 cm) -- should be 1930
  • {{convert|761.0|in|cm|abbr=on}} => 761.0 in (1,933 cm) -- should be 1933
  • {{convert|762.0|in|cm|abbr=on}} => 762.0 in (1,935 cm) -- should be 1935
  • {{convert|763.0|in|cm|abbr=on}} => 763.0 in (1,938 cm) -- should be 1938

Putting 0.025400000000 instead of 0.0254 in the code won't even help --JimWae (talk) 09:59, 4 July 2010 (UTC)Reply

Not sure if it matters, I just created Template:Convert/prand. I don't know if relates to a problem you seemed to have found. wiooiw (talk) 13:05, 4 July 2010 (UTC)Reply
It's doing just what it was designed to do, that is rounding according to the precision of the input number. To convert 765inches to 1943 centimetres would be to introduce false precision: the first is precise to the nearest inch & second to the nearest centimetre. The template does, however, allow for some degree of false precision. There are four ways to get extra precision.
  1. where the precision of the output is greater than that of the input but still less than twice, e.g. {{convert|123|nmi|km}} gives "123 nautical miles (228 km)" even though nautical miles are bigger than kilometres, the thing is that they are less than twice as big
  2. where following the rule above (i.e. round to allow up to twice the precision) would give only one significant figure, e.g. 70 inches is precise to the nearest ten inches but it converts to 180 centimetres not 200 centimetres
  3. where you specify the precision you're after
  4. tweak the code e.g. as Wikid suggests below
There is nothing wrong with the template if you need extra precision, tell it to give you extra precision. Jimp (talk) 01:20, 19 January 2012 (UTC)Reply

Problem in rounding for significant digits

change

No, I found the problem a couple of days ago. It is because numbers like 76 and 760 have only 2 significant figures that converting to cm leaves only 2 significant figures in the output. This is actually in accord with a common rule for sig figs when multiplying (that output should have no more sig figs than the input with the least number of sig figs). However, it produces unexpected results (like rounding people's heights to nearest 10 cm & converting 751 inches to a greater distance than 760 inches) -- and not the same as on regular wikipedia. It is rounding to nearest 10 cm for outputs above - which is 4 times LESS precise than an inch is - whereas going one more sig fig would be only 2.54 times MORE precise than the input. This template is not the one to use for people's heights. Unfortunately, the height template only converts to metres, and there is no way to get it to output in cm. Height in cm is the more common way to express height (rather than [in hundreths of] a m) in Canada & apparently Australia too.--JimWae (talk) 19:18, 4 July 2010 (UTC)Reply

It should not be converting 730 inches to the same value as 760 inches--JimWae (talk) 04:24, 5 July 2010 (UTC)Reply

Template:Ft in to m is where to look next --JimWae (talk) 05:20, 5 July 2010 (UTC)Reply

Yes, four times less precise but less than five times less precise (by design). As mentioned above, you can specify the precision you desire using a parameter, there's no need to use a whole new template. Jimp (talk) 01:26, 19 January 2012 (UTC)Reply

Fix Convert/cm from sandbox

change

This is a request to fix Template:Convert/cm using the sandbox version to correct the rounding of the result by 1 extra digit when the amount is a whole number (integer). The fix resets the value of precision parameter "j=" in the same way Template:Convert/ft sets the value of j, depending on "floor({{{1}}})" to detect the whole-number amount.

After updating from Template:Convert/cm/sandbox, results should match:

  • Expected: {{convert|70|in|cm}} → 70 inches (180 cm)
  • Currently: {{convert|70|in|cm}} → 70 inches (180 cm)
  • Expected: {{convert|74|in|cm}} → 74 inches (188 cm)
  • Currently: {{convert|74|in|cm}} → 74 inches (190 cm)
  • Expected: {{convert|76|in|cm}} → 76 inches (193 cm)
  • Currently: {{convert|76|in|cm}} → 76 inches (190 cm)
  • Expected: {{convert|6|ft|4|in|cm}} → 6 feet 4 inches (193 cm)
  • Currently: {{convert|6|ft|4|in|cm}} → 6 feet 4 inches (193 cm)
  • Expected: {{convert|7|ft|cm}} → 7 feet (213 cm)
  • Currently: {{convert|7|ft|cm}} → 7 feet (210 cm)

After updating Convert/cm, then results should match. -Wikid77 14:06, 18 January 2012 (UTC)Reply

  Done -DJSasso (talk) 15:29, 31 January 2012 (UTC)Reply

Testing code

change

{{editprotected}}

The following is not needed.

<!--testing code follows-->{{#switch:{{{disp}}}|br={{convert/test/Dbr}}|/={{convert/und}}}}{{convert/test/A{{{abbr|}}}}}

It's just to keep track of what pages are using what parameters. Jimp (talk) 01:34, 19 January 2012 (UTC)Reply

Well, if it does not hurt, I'd not change it actually. Maybe it is good that this keeps track of what pages are using what parameters. -Barras (talk) 13:38, 26 January 2012 (UTC)Reply

per is not a basic word

change

{{editprotected}}

per is not a basic word. Hour, gram, liter and meter are. Output strings should to be of the format miles/hour and feet/seecond rather than miles per hour and feet per second. Josh Parris 07:53, 4 March 2012 (UTC)Reply

This template doesn't generate "per", it's the subtemplates. Also, you can simply make the instance use abbreviation by adding |abbr=on. Osiris (talk) 07:15, 7 March 2012 (UTC)Reply
Should we make |abbr=on the default then? Josh Parris 08:14, 7 March 2012 (UTC)Reply
It is the default under MOS:UNITS (on enwp) to abbreviate all but the first instance. As for making it the default in the template, it'd be more effort than it'd be worth. You'd need someone who is familiar with the system, but I'd estimate that it would require changing about 4–5 hundred templates. Osiris (talk) 08:22, 7 March 2012 (UTC)Reply
Not so; I believe if you change
A{{#switch:{{{abbr}}}|off=none|def=off|{{{abbr|off}}}}}
to
A{{#switch:{{{abbr}}}|off=none|def=on|{{{abbr|on}}}}}
then you're done. Josh Parris 12:57, 7 March 2012 (UTC)Reply
Having said that, the abbr setting generates things like kph rather than kilometers/hour, so it's not very easy to read. Josh Parris 12:59, 7 March 2012 (UTC)Reply
Personally, I think most abbreviations are harder for English learners to understand than the expanded forms. You can try out your theory on the /test page if you like. Osiris (talk) 13:04, 7 March 2012 (UTC)Reply

We don't only use basic words. Sometimes we are forced to use more complex words. This might be one case. -DJSasso (talk) 13:35, 7 March 2012 (UTC)Reply

Here's a quick and easy solution: http://www.mediawiki.org/wiki/Extension:StringFunctions#.23replace: and swap " per " for "/"; all we need to do is get StringFunctions installed. Josh Parris 12:41, 9 March 2012 (UTC)Reply

Calories to Joule not correctly converted

change

Convert 1000 calories to kJ: 1,000 calories (4,200 kJ)

Since 1 Cal = 4.184 Joule it should be: 1 kCal (4.2 kJ)

So, there's a factor of 1000 missing or too much.

Return to "Convert" page.