syl3r86 / inventory-plus

A Foundry VTT module to enhance the dnd5e inventory. Allows to customize your Inventory in various ways.
8 stars 12 forks source link

Strange numbers in cumulative weight #23

Open Gieff opened 3 years ago

Gieff commented 3 years ago

A very specific case, especially whit kilos insted of lbs. If the item have a very small weight, the number has a round error https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

image

I resolved with a function that return better looking numbers (from line:459)

let reduce = (number, precision) => {
    let factor = Math.pow(10, precision);
    let n = precision < 0 ? number : 0.01 / factor + number;
    return Math.round( n * factor) / factor;
}
return reduce(weight,3);

or in alternative the same solution used for the coins weight can be applied: return Number(weight).toFixed(2);

or using Math.js (but must be an active dependecy): return Math.format(weight,{format:14})

image