0

I have a float, say 1762423.55, which I want to format as 1.76M, i.e. with three significant digits and with a SI prefix.

In Javascript this accessible with the s type in d3.format.

But in Python,

'{:s}'.format(1762423.55)

fails with a ValueError: Unknown format code 's' for object of type 'float'.

Is the SI format accessible through another standard type format in Python? If not, where on GitHub should I ask for it?

Marc Wouts
  • 669
  • 6
  • 8
  • look [here](https://stackoverflow.com/a/32093034/6045800) – Tomerikoo Jul 11 '19 at 08:17
  • Thanks for the links. I'd prefer not to use an additional script or library - anyone knows where on GitHub I can ask (or contribute) that feature to `str.format`? – Marc Wouts Jul 11 '19 at 08:29
  • @MarcWouts you could ask but that doesn't mean they would add it straight away. The beauty of Python is that you can extend it with your desired behaviour through functions and methods given a base set of functionality. – mrbolichi Jul 11 '19 at 08:35

0 Answers0