Display a decimal in scientific notation

from decimal import Decimal ‘%.2E’ % Decimal(‘40800000000.00000000000000’) # returns ‘4.08E+10′ In your ‘40800000000.00000000000000’ there are many more significant zeros that have the same meaning as any other digit. That’s why you have to tell explicitly where you want to stop. If you want to remove all trailing zeros automatically, you can try: def format_e(n): a=”%E” … Read more

Convert float to String and String to float in Java

Using Java’s Float class. float f = Float.parseFloat(“25″); String s = Float.toString(25.0f); To compare it’s always better to convert the string to float and compare as two floats. This is because for one float number there are multiple string representations, which are different when compared as strings (e.g. “25” != “25.0” != “25.00” etc.)

Format / Suppress Scientific Notation from Pandas Aggregation Results

Granted, the answer I linked in the comments is not very helpful. You can specify your own string converter like so. In [25]: pd.set_option(‘display.float_format’, lambda x: ‘%.3f’ % x) In [28]: Series(np.random.randn(3))*1000000000 Out[28]: 0 -757322420.605 1 -1436160588.997 2 -1235116117.064 dtype: float64 I’m not sure if that’s the preferred way to do this, but it works. … Read more

Force R not to use exponential notation (e.g. e+10)?

This is a bit of a grey area. You need to recall that R will always invoke a print method, and these print methods listen to some options. Including ‘scipen’ — a penalty for scientific display. From help(options): ‘scipen’: integer. A penalty to be applied when deciding to print numeric values in fixed or exponential … Read more

How can I remove the decimal part from JavaScript number?

You could use… Math.trunc() (truncate fractional part, also see below) Math.floor() (round down) Math.ceil() (round up) Math.round() (round to nearest integer) …dependent on how you wanted to remove the decimal. Math.trunc() isn’t supported on all platforms yet (namely IE), but you could easily use a polyfill in the meantime. Another method of truncating the fractional … Read more

Using String Format to show decimal up to 2 places or simple integer

Sorry for reactivating this question, but I didn’t find the right answer here. In formatting numbers you can use 0 as a mandatory place and # as an optional place. So: // just two decimal places String.Format(“{0:0.##}”, 123.4567); // “123.46” String.Format(“{0:0.##}”, 123.4); // “123.4” String.Format(“{0:0.##}”, 123.0); // “123” You can also combine 0 with #. … Read more

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