Template talk:Deg2DMS
This template does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||
|
Minus signs?
editHyphens for negative values? Even if a minus sign is passed in to the template? Surely should be fixed. Lithopsian (talk) 19:42, 24 August 2020 (UTC)
Template-protected edit request on 13 November 2020
editThis edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Please change the apostrophe symbols (encoded as '
) to correct (angled) ′ (′) and double-″ (″) symbols, to match e.g. Template:DEC.
More specifically, the code is changed to
<!-- -->{{#expr: FLOOR({{{1|0}}})}}° <!-- -->{{#expr: FLOOR( ((({{{1|0}}}) - FLOOR({{{1|0}}})) round 14 )*60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!-- -->{{#expr: (((({{{1|0}}})-FLOOR({{{1|0}}}))*60) - FLOOR( ((({{{1|0}}})-FLOOR({{{1|0}}})) round 14 )*60))*60 round {{#if:{{{p|}}}|{{{p|}}}|3}}}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}
Er... while you're at it, that equation for the seconds is a bit silly. It's more conveniently written as (x*60 - floor(x*60)) * 60 round 3, or in full:
<!-- -->{{#expr: FLOOR({{{1|0}}})}}° <!-- -->{{#expr: FLOOR( ((({{{1|0}}}) - FLOOR({{{1|0}}})) round 14 )*60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!-- -->{{#expr: (60*({{{1|0}}})-floor(60*({{{1|0}}}))) * 60 round {{#if:{{{p|}}}|{{{p|}}}|3}}}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}
92.119.17.10 (talk) 00:10, 14 November 2020 (UTC)
- Partly done: The first request is done. For the second, please put the code into the sandbox and create some testcases to show the difference. Thanks. – Jonesey95 (talk) 15:06, 14 November 2020 (UTC)
- @Jonesey95: Thank you! For the second edit, here's an example table comparing the output of the two. (The code above is in Template:X40, and Template:X41 is a comparison helper
|-
- @Jonesey95: Thank you! For the second edit, here's an example table comparing the output of the two. (The code above is in Template:X40, and Template:X41 is a comparison helper
| {{{1}}} || {{Deg2DMS|{{{1}}}|p={{{p|}}}}} || {{X40|{{{1}}}|p={{{p|}}}}}
As you can see, the replacement is equivalent, but shares certain problems with the original (see the 7th, 8th and 9th example below, as well as the last). I can come up with a replacement that fixes everything, but that's a bit more work. Now implemented in Template:X42.
Any opinions? 92.119.17.10 (talk) 00:05, 16 November 2020 (UTC)
- The working code, preserved for when Template:X42 gets erased:
{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) / 3600)}}° <!-- -->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) mod 3600 / 60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!-- -->{{#expr: ({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) fmod 60}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Per discussion and examples above, replace the logic with
<!-- -->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) / 3600)}}° <!-- -->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) mod 3600 / 60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!-- -->{{#expr: ({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) fmod 60}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}
This converts the entire angle to seconds and rounds to the specified precision before breaking it apart into degrees and minutes, avoiding certain corner case bugs where the different components would be rounded in different directions, or seconds would be rounded to 60. 92.119.17.10 (talk) 03:31, 16 November 2020 (UTC)
- Done looking good. For future information, the best place to sandbox your code is the template's own sandbox, in this case Template:Deg2DMS/sandbox and testing can be done in Template:Deg2DMS/testcases — Martin (MSGJ · talk) 09:21, 18 November 2020 (UTC)
- Sorry for the delay in getting to this one; I wanted to test it more thoroughly. It looks like the
|p=
parameter is not working properly. See Template:Deg2DMS/testcases#Precision parameter. I have put the old template code into the sandbox to show the difference. – Jonesey95 (talk) 15:06, 18 November 2020 (UTC)- @Jonesey95 and MSGJ: H'm, the new error is interesting. The problem is not with
|p=
proper; it's just that the value|p=4
happens to trigger a window where thefmod
is revlealing some rounding in the lsbits that is causing a mess. But rounding the arc seconds before thefmod
is critical to not displaying 60 seconds. How about just a "redundant" re-rounding after thefmod
? I've put that in the sandbox, which seems to work. There's a comment in the wikisource because it's ugly. 64.44.80.252 (talk) 07:13, 19 November 2020 (UTC)- Seems to work, so I have copied it to the live template. I will trust other editors to point out any problems with the new code. The test cases page could use some more examples from real-world use in articles. – Jonesey95 (talk) 17:28, 19 November 2020 (UTC)
- @Jonesey95 and MSGJ: H'm, the new error is interesting. The problem is not with
- Sorry for the delay in getting to this one; I wanted to test it more thoroughly. It looks like the