$num(x,y) should not truncate decimal numbers to the whole part

reopening old issue: [X] $num doesn’t work as described

OS: Windows 10
mp3tag: 3.31a

According to Docs ( Scripting Functions – Mp3tag Documentation ),
"returns string x interpreted as decimal number, padded with leading zeros from the left up to y digits. It ignores anything from the first non-numeric character, or results in 0 if the string is not numeric."

$num(x,y) should handle decimal numbers, but instead, it truncates the number to the whole value.

Expected: $num(1.5,2) = 01**.5**

Actual: $num(1.5,2) = 01

My Action: $num(%series-part%,2)

Perhaps "decimal number" is an unlucky term as MP3tag only handles integer numbers.
(This is also mentioned in the documentation:

Arithmetic Functions

Integer arithmetic only, operations support up to 64 arguments.

In that context $num() works as described: it ignores anything from the first non-numeric character onwards which is the dot in your your example. That leaves only the "1" which is then padded to show 2 digits.

Agreed. While I would (obviously) like decimals to be handled, If this is not going to make the priority list, I would suggest changing the docs: "decimal" -> "integer", to avoid confusion.

An emulation would be:
$num($div($replace(1.5,.,),10),2).$mod($replace(1.5,.,),10)

Thanks @ohrenkino . I updated your suggestion to also handle whole numbers:
$ifgreater($strchr(%series-part%,.),0,$num($div($replace(%series-part%,.,),10),2).$mod($replace(%series-part%,.,),10),$num(%series-part%,2))

Thanks for pointing, I've updated the documentation accordingly.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.