Format Number like Stack Overflow (rounded to thousands with K suffix)

Like this: (EDIT: Tested) static string FormatNumber(int num) { if (num >= 100000) return FormatNumber(num / 1000) + “K”; if (num >= 10000) return (num / 1000D).ToString(“0.#”) + “K”; return num.ToString(“#,0”); } Examples: 1 => 1 23 => 23 136 => 136 6968 => 6,968 23067 => 23.1K 133031 => 133K Note that this will … Read more

Can you format pandas integers for display, like `pd.options.display.float_format` for floats?

You could monkey-patch pandas.io.formats.format.IntArrayFormatter: import contextlib import numpy as np import pandas as pd import pandas.io.formats.format as pf np.random.seed(2015) @contextlib.contextmanager def custom_formatting(): orig_float_format = pd.options.display.float_format orig_int_format = pf.IntArrayFormatter pd.options.display.float_format=”{:0,.2f}”.format class IntArrayFormatter(pf.GenericArrayFormatter): def _format_strings(self): formatter = self.formatter or ‘{:,d}’.format fmt_values = [formatter(x) for x in self.values] return fmt_values pf.IntArrayFormatter = IntArrayFormatter yield pd.options.display.float_format = orig_float_format pf.IntArrayFormatter … Read more

How to make Python format floats with certain amount of significant digits?

You’ll want the g modifier for format that drops insignificant zeroes; >>> “{0:.6g}”.format(5.5657188485) ‘5.56572’ >>> “{0:.6g}”.format(3.539) ‘3.539’ Sorry, my update also includes the fact that I am restricted to using Python 2.4.3, which does not have format() function. The format specifiers work even without the .format() function: >>> for i in a: … print ‘%.6g’ … Read more

Add .00 (toFixed) only if number has less than two decimal places

Here you go: function addZeroes(num) { // Convert input string to a number and store as a variable. var value = Number(num); // Split the input string into two arrays containing integers/decimals var res = num.split(“.”); // If there is no decimal point or only one decimal place found. if(res.length == 1 || res[1].length < … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)