$div decimal places?


#1

Can the $div scripting function be made to return a given number of decimal places? Or can I do something similar with $mod?

thanks


#2

Mp3tag scripting language supports integer mathematics only.
So let us see your real world example and maybe we can solve the problem.

DD.20071115.0930.CET


#3

OK thanks DetlevD

I want to show the tag size in kB so I need something like $div(%_tag_size_prepended%, 1024). For 1 decimal place I guess I need something like:

$div(%_tag_size_prepended%,1024).$div($mul($mod(%_tag_size_prepended%, 1024), 10), 1024)k

but its not rounding up. Any suggestions?


#4

This might round in the right way:

$ifgreater($mod($div($mul(%_tag_size_prepended%,100),1024),10),4,$div($add(1,$div($div($mul(%_tag_size_prepended%,100),1024),10)),10)'.'$mod($add(1,$div($div($mul(%_tag_size_prepended%,100),1024),10)),10),$div($div($div($mul(%_tag_size_prepended%,100),1024),10),10)'.'$mod($div($div($mul(%_tag_size_prepended%,100),1024),10),10))' KB'

e. g. 672615 to 656.9 KB
e. g. 13648 to 13.3 KB

DD.20071126.2050


#5

Wow that seems to work! thanks DetlevD. :smiley: