Trim to a predetermined precision to generate predictable keys based on floating point numbers. JavaScript example
const precision = Math.pow(10, 4); // where 4 is number of decimal places to retain const a = 12.5678912331; b = 13.75324122; c = 21.32112221 const key = '' + Math.floor(a * precision) + '_' + Math.floor(b * precision) + '_' + Math.floor(c * precision); const aMap = new Map(); aMap.set(key, 'some value');
Useless fact: this is taken from the code used to index vertices in three-dimensional objects. By setting lower accuracy, this allows you to combine nearby peaks.
Pawel source share