I have seen at least one other question where a user has had issues with using Decimals as map keys (his issue was interchangeably using ints vs decimals), but it isn't the same issue I'm having, where Decimal keys appear to be treated as Strings for comparison:
Map<Decimal,String> m = new Map<Decimal,String>();
m.put(3.10,'Decimal key with trailing zero');
List<Decimal> keys = new List<Decimal>(m.keySet());
Decimal d = keys.get(0);
//Both of these statements should be true. If not, at the very least,
// they should both be false
System.debug(d+' = 3.1? '+(d == 3.1));//3.10 = 3.1? true
System.debug('CONTAINS KEY 3.1? '+m.containsKey(3.1));//CONTAINS KEY 3.1? false
//I can successfully add a Decimal key equivalent to one already in the Collection
m.put(3.1,'Equivalent Decimal key without trailing zero');
System.debug('SIZE = '+m.keySet().size());//SIZE = 2
//Again, the Decimal objects are equal
Decimal d1 = 3.1;
Decimal d2 = 3.10;
System.debug('Values are equal? '+(d1 == d2));//Values are equal? true
//But even if I remove the shorter value....
String removeValue = m.remove(3.1);
System.debug('removeValue = '+removeValue);//removeValue = Equivalent Decimal key without trailing zero
//...It will not match in the get statement either
String res = m.get(d1);
System.debug('Res == null? '+(res == null));//Res == null? true
Am I missing something?
hashCode
, even if its value stays the same.