# Sorting negative & positive numerical values

**URL:** <https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879>\
**Category:** Support\
**Created:** [February 15, 2020, 5:24pm UTC](https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879 "2020-02-15T17:24:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Claudio](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@Claudio](https://community.mp3tag.de/u/Claudio)\
**Post date:** [February 15, 2020, 5:24pm UTC](https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879/1 "2020-02-15T17:24:14Z")

</div>

MP3Tag v3.00

Hello,  
How to sort ascending a column that has positive and negative values so the result would go from negative to positive?

Here is the column definition:  
name: ReplayGain-tr  
Value: $replace(%REPLAYGAIN\_TRACK\_GAIN%, dB,)  
Field: %REPLAYGAIN\_TRACK\_GAIN%  
Sort by: $replace(%REPLAYGAIN\_TRACK\_GAIN%, dB,)

Notes: I remove the "dB" so I do a numerical sort. I tried with and without = same result.

It's a bit ackward:  
a. the sort does not see the negative sign  
b. it sort the integer portion ascending from 0 to 9, then sorts the fractional portion descending

My objective: sort the field so it goes from biggest negative, to zero, then to the biggest positive (like in a spreadsheet)

Thank you for any assistance.  
Regards

![screenshot_0](https://community.mp3tag.de/uploads/default/original/2X/1/15953c7ac310ef98e0059dc2d0e9d185d8213174.jpeg)

 ![screenshot_1](https://community.mp3tag.de/uploads/default/original/2X/f/fb6883a9844313f95ed4e5bc8e1d3c70e7011a11.jpeg)

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [February 15, 2020, 5:32pm UTC](https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879/2 "2020-02-15T17:32:43Z")

</div>

Sort by `$num($replace(%REPLAYGAIN_TRACK_GAIN%,'.',),1)` should do the trick.

---

<div class="post-metadata">

**Author:** ![Claudio](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@Claudio](https://community.mp3tag.de/u/Claudio)\
**Post date:** [February 15, 2020, 6:03pm UTC](https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879/3 "2020-02-15T18:03:24Z")

</div>

Hello Mister Florian 🙂

Thx for your superQuick reply...

The $num did not do much, BUT removing the decimal point solved it 😃  
So here is the final version:  
`$replace(%REPLAYGAIN_TRACK_GAIN%, dB,,.,)`  
So "-0.05 dB" becomes -\> "-005"  
then the sort is negative\>\>\>0\>\>\>positive.

Thank you again.

---

<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:** [March 16, 2020, 6:03pm UTC](https://community.mp3tag.de/t/sorting-negative-positive-numerical-values/47879/4 "2020-03-16T18:03:31Z")

</div>

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