azaitsev / millify Goto Github PK
View Code? Open in Web Editor NEWConvert long numbers into a human-readable format in Python
License: MIT License
Convert long numbers into a human-readable format in Python
License: MIT License
Using 999999 with millify should return 1M but it returns 1000k
>>> from millify import millify
>>> millify('999999')
>>> '1000k'
Sometimes you want a fixed number of characters to be used for a number (for logging for example).
With 5 characters (this includes numbers, decimal points and magnitude):
4000000 => 4.00M
40000 => 40.0K
4000 => 4.00K
400 => 0.40K (400 and 400.0 are wrong as they take 3 and 5 places)
40 => 0.04K or 40.00
4 => 4.000
The function prettify has a self-loop, but it doesn't account for a different character in the loop it just affects the first iteration.
This is the solution to the error.
def prettify(amount, separator=','): """Separate with predefined separator.""" orig = str(amount) new = re.sub("^(-?\d+)(\d{3})", "\g<1>{0}\g<2>".format(separator), str(amount)) if orig == new: return new else: return prettify(new, separator)
Notice issued in public interest
Could you make a reversed version of your library? One that converts shortened prefixes to their longer number counterparts.
That would be amazing. Thanks for the project as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.