bobthecow / genghis

The single-file MongoDB admin app
http://genghisapp.com
MIT License
1.45k stars 165 forks source link

Bug in Genghis.Util.humanizeSize #167

Closed thomas-riccardi closed 10 years ago

thomas-riccardi commented 10 years ago
Genghis.Util.humanizeSize(144.05351170568562)
// result: '1445 Bytes'

I found this in the 'Avg. object size' in some collections.

Why is Genghis.Util.round so complicated?

bobthecow commented 10 years ago

Thank you for reporting this. It has been fixed in v2.3.11.

Genghis.Util.round is so complicated because it's poorly named and has to deal with a lot of edge cases :)

The bug was in humanizeSize, though.

size = Genghis.Util.round(size, 2).toString().replace(/\.0+/, '');

That regex is missing an anchor, so it removes the .0 in 144.05 and ends up with 1445.

thomas-riccardi commented 10 years ago

Thanks for the quick fix!

bobthecow commented 10 years ago

No problem.