# floating point arithmetic in a script

**URL:** <https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693>\
**Category:** Support\
**Created:** [April 28, 2014, 3:47pm UTC](https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693 "2014-04-28T15:47:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuck](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chuck](https://community.mp3tag.de/u/chuck)\
**Post date:** [April 28, 2014, 3:47pm UTC](https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693/1 "2014-04-28T15:47:54Z")

</div>

Hello,

I am writing a script to process some tags which are floating point numbers.  
I need to set a new tag to the difference between these floats. I have tried to use $sub,  
but it appears that $sub only works if the numbers are integers. Is there a way to  
perform floating point arithmetic?

Thanks,

Chuck

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [April 28, 2014, 3:56pm UTC](https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693/2 "2014-04-28T15:56:19Z")

</div>

> [@Chuck](#):
>
> ... Is there a way to  
> perform floating point arithmetic?
> 
> Thanks,
> 
> Chuck

Not out of the box, I would say.  
But you can use home-brew arithmetics with $div and $mod for the remainder. and naturally $add and $sub to add integers.  
Yet, I wonder if it would not be easier to export the data, process it with a real calculation program and then re-import the result.

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [April 28, 2014, 5:29pm UTC](https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693/3 "2014-04-28T17:29:34Z")

</div>

> [@Chuck](#):
>
> I am writing a script to process some tags which are floating point numbers. I need to set a new tag to the difference between these floats. ...  
> Is there a way to perform floating point arithmetic?

I do not think, that you have seen any tag-field having really a floating point number.  
You might have seen the textual representation of a floating point number.

Mp3tag supports only integer math.

But there is a way to work with 'floating point' number strings.  
Make sure to format the decimal part of all number strings (on the right side of the decimal point), so that all decimal parts get the same length (add rightmost '0' characters).  
Then remove the decimal point from the number strings.  
Now you can do integer arithmetic.

At end you might insert the decimal point at the right place into the numberstring.

**Example**

**Subtract Number2 from Number1 N1 \<== '123.45' N2 \<== '0.54321' N1 \<== $regexp(%N1%$repeat('0',6),'^(\d+)\.(\d{6}).+$','$1$2') N2 \<== $regexp(%N2%$repeat('0',6),'^(\d+)\.(\d{6}).+$','$1$2') N3 \<== $sub(%N1%,%N2%) N3 \<== $cutRight(%N3%,6)'.'$right(%N3%,6) ... or ... N3 \<== $div(%N3%,1000000)'.'$mod(%N3%,1000000) N3 = '122.906790' N3 \<== $trimRight(%N3%,'0') N3 = '122.90679'**

... or ...

**Example**

**Subtract Number2 from Number1 N1 \<== '123.45' N2 \<== '0.54321' N0 \<== $ifgreater($len($regexp(%N1%,'^\d+\.',)),$len($regexp(%N2%,'^\d+\.',)),$len($regexp(%N1%,'^\d+\.',)),$len($regexp(%N2%,'^\d+\.',))) N1 \<== $regexp(%N1%$repeat('0',%N0%),'^(\d+)\.(\d{'%N0%'}).+$','$1$2') N2 \<== $regexp(%N2%$repeat('0',%N0%),'^(\d+)\.(\d{'%N0%'}).+$','$1$2') N3 \<== $sub(%N1%,%N2%) N3 \<== $cutRight(%N3%,%N0%)'.'$right(%N3%,%N0%) ... or ... N3 \<== $div(%N3%,'1'$repeat('0',%N0%))'.'$mod(%N3%,'1'$repeat('0',%N0%)) N3 = '122.90679'**Begin Action Group **Test\_2014#20140503.SubtractNum2FromNum1** 

Action #1  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT1**  
_Formatstring:_ **123.45**

 

Action #2  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT2**  
_Formatstring:_ **0.54321**

 

Action #3  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_L1**  
_Formatstring:_ **$len($regexp(%MY\_CALC\_FLT1%,'^\d+.',))**

 

Action #4  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_L2**  
_Formatstring:_ **$len($regexp(%MY\_CALC\_FLT2%,'^\d+.',))**

 

Action #5  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_L3**  
_Formatstring:_ **$ifgreater(%MY\_CALC\_L1%,%MY\_CALC\_L2%,%MY\_CALC\_L1%,%MY\_CALC\_L2%)**

 

Action #6  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_INT1**  
_Formatstring:_ **$regexp(%MY\_CALC\_FLT1%$repeat('0',%MY\_CALC\_L3%),'^(\d+).(\d{'%MY\_CALC\_L3%'}).+$','$1$2')**

 

Action #7  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_INT2**  
_Formatstring:_ **$regexp(%MY\_CALC\_FLT2%$repeat('0',%MY\_CALC\_L3%),'^(\d+).(\d{'%MY\_CALC\_L3%'}).+$','$1$2')**

 

Action #8  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_INT3**  
_Formatstring:_ **$sub(%MY\_CALC\_INT1%,%MY\_CALC\_INT2%)**

 

Action #9  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT3**  
_Formatstring:_ **$cutRight(%MY\_CALC\_INT3%,%MY\_CALC\_L3%)'.'$right(%MY\_CALC\_INT3%,%MY\_CALC\_L3%)**

 

Action #10  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT3**  
_Formatstring:_ **$trimRight(%MY\_CALC\_FLT3%,'0')**

 

Action #11  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT3**  
_Formatstring:_ **$trimRight(%MY\_CALC\_FLT3%,'.')**

 

Action #12  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **MY\_CALC\_FLT3**  
_Formatstring:_ **$replace(%MY\_CALC\_FLT3%,'.-','-.')**

 

Action #13  
_Actiontype 9:_ **Remove fields**  
_Fields to remove (semicolon separated):_ **MY\_CALC\_FLT1;MY\_CALC\_FLT2;MY\_CALC\_INT1;MY\_CALC\_INT2;MY\_CALC\_INT3;MY\_CALC\_L1;MY\_C  
ALC\_L2;MY\_CALC\_L3**

 

End Action Group **Test\_2014#20140503.SubtractNum2FromNum1** (13 Actions)

 

DD.20140428.2130.CEST, DD.20140429.1414.CEST, DD.20140503.1200.CEST

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/floating-point-arithmetic-in-a-script/15693/4 "2026-02-09T12:25:01Z")

</div>

Closed on February 9, 2026, 12:25pm UTC


