mkaz / termgraph

a python command-line tool which draws basic graphs in the terminal
MIT License
3.14k stars 165 forks source link

Fix fractional numbers in cvt to readable #88

Open mtejada11 opened 3 years ago

mtejada11 commented 3 years ago

I've made a fix to the function 'cvt_to_readable' so that it displays fractional values correctly. Before the fix, when the value of 'index' was negative in the case of a small fractional number, for example 0.000001, the suffixes 'K', 'M', 'B', etc. would still be added. With this modification, suffixes such as 'e-003' are added for fractional numbers less than 1.0. Also fixed case where 'index' would result in a value greater than the one corresponding to 'T'.

There was also a spacing inconsistency, for example both '1.24 K' and '12.35K' would be generated for values 1234 and 12345. This was fixed by changing the default format from "5.2f" to ".2f".

The test program has been updated to test for the changes being submitted. Please review and accept this pull request if you wish. I really like termgraph. It's a great command-line utility. Thanks.