Question: Basically, I have a set of BigDecimal values for example
**[3.2,3.10,3.12,3.17,3.9].**

I want to sort them based on the values after the dot using java.
The expected output should be like **[3.2,3.9,3.10,3.12,3.17]**.
how do I write a code for this can you please help?

Answer: 
It seems you actually want to process version numbers, so I strongly discourage from abusing `BigDecimal` for that purpose. It’s too easy to accidentally confuse your logic with `BigDecimal`’s original numeric semantics.

Create your own class reflecting the actual purpose, e.g.

```java
public record Version(int major, int minor) implements Comparable<Version> {
    public static Version parse(String s) {
        int dot = s.indexOf('.');
        return dot < 0? new Version(Integer.parseInt(s), 0):
            new Version(Integer.parseInt(s, 0, dot, 10),
                        Integer.parseInt(s, dot + 1, s.length(), 10));
    }

    @Override
    public int compareTo(Version v) {
        return major != v.major?
            Integer.compare(major, v.major): Integer.compare(minor, v.minor);
    }

    @Override
    public String toString() {
        return major + "." + minor;
    }
}

```

With such a class, you’ll never run into the problem of contradicting semantics.

When you use it with ,e.g.

```java
Stream.of("3.2","3.10","3.12","3.17","3.9").map(Version::parse)
    .sorted().forEachOrdered(System.out::println);

```

It will print

```none
3.2
3.9
3.10
3.12
3.17

```
Create a method that returns the decimal part according to the `scale` of the given number  

(e.g. calling it with `3.10` will return `10`):

```
private static BigDecimal decimalPart(BigDecimal num) {
    var dec = num.remainder(BigDecimal.ONE);    // decimal part (e.g. 0.10)
    var adj = dec.movePointRight(dec.scale());
    return adj;
}

```

then use that to create a `Comparator` used for sorting:

```
var byDecimalPart = Comparator.comparing(SortedDecimal::decimalPart);
var sorted = input
    .stream()
    .sorted(byDecimalPart)
    .toList();    // or .collect(...) or .forEach(...)

```

probably not correct for negative numbers (missing specification)