number-formatting

number_format() php remove trailing zeros

一笑奈何 提交于 2020-07-06 20:59:32
问题 Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 50.0 => 50 50.00 => 50 50 => 50 Is there a way to do this with just a standard number_format() ? 回答1: You can add 0 to the formatted string. It will remove trailing zeros. echo number_format(3.0, 1, ".", "") + 0; // 3 A Better Solution: The above solution fails to work for specific locales. So in that

number_format() php remove trailing zeros

て烟熏妆下的殇ゞ 提交于 2020-07-06 20:58:20
问题 Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 50.0 => 50 50.00 => 50 50 => 50 Is there a way to do this with just a standard number_format() ? 回答1: You can add 0 to the formatted string. It will remove trailing zeros. echo number_format(3.0, 1, ".", "") + 0; // 3 A Better Solution: The above solution fails to work for specific locales. So in that

PHP gives incorrect results when formatting long numbers

半世苍凉 提交于 2020-06-27 06:49:25
问题 I am working with huge numbers for website purposes and I need long calculation. When I echo a long number I don't get the correct output. Example // A random number $x = 100000000000000000000000000; $x = number_format($x); echo "The number is: $x <br>"; // Result: 100,000,000,000,000,004,764,729,344 // I'm not getting the value assigned to $x 回答1: Your number is actually too big for php standard integers. php uses 64 bit integers which can hold values within range -9223372036854775808 ( PHP

Easy way to add thousand separator to numbers in Python pandas DataFrame

隐身守侯 提交于 2020-06-08 20:48:52
问题 Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it? 回答1: When formatting a number with , you can just use '{:,}'.format : n = 10000 print '{:,}'.format(n) n = 1000.1 print '{:,}'.format(n) In pandas, you can use the formatters parameter to to_html as discussed here. num_format = lambda x: '{:,}'.format(x) def build_formatters(df, format): return { column:format for column, dtype in df

Easy way to add thousand separator to numbers in Python pandas DataFrame

可紊 提交于 2020-06-08 20:48:07
问题 Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it? 回答1: When formatting a number with , you can just use '{:,}'.format : n = 10000 print '{:,}'.format(n) n = 1000.1 print '{:,}'.format(n) In pandas, you can use the formatters parameter to to_html as discussed here. num_format = lambda x: '{:,}'.format(x) def build_formatters(df, format): return { column:format for column, dtype in df

How to stop Windows 10 Mail app to create links/contacts from numbers?

自古美人都是妖i 提交于 2020-05-17 06:05:18
问题 Windows 10 Mail app converts some numbers to links/contacts automatically in html emails. Usually numbers or part of numbers with 000-s: How can i stop this? I've tried with "text-decoration:none; text-transform:none;" but it didn't worked. Thanks! 回答1: This is very common, and occurs also in many mobile apps. What they are trying to do is be 'helpful' and convert them to phone numbers (typically). To get rid of this, you can add an odd character that will break their find & replace: ‌ (zero

How to stop Windows 10 Mail app to create links/contacts from numbers?

我的未来我决定 提交于 2020-05-17 06:04:01
问题 Windows 10 Mail app converts some numbers to links/contacts automatically in html emails. Usually numbers or part of numbers with 000-s: How can i stop this? I've tried with "text-decoration:none; text-transform:none;" but it didn't worked. Thanks! 回答1: This is very common, and occurs also in many mobile apps. What they are trying to do is be 'helpful' and convert them to phone numbers (typically). To get rid of this, you can add an odd character that will break their find & replace: ‌ (zero

Java - NumberValue to String without Currency sign

♀尐吖头ヾ 提交于 2020-05-15 10:08:06
问题 I am trying to format a NumberValue as a String in the current locale format. For example, for Locale.Germany these would be the results I am trying to get: 1 -> 1,00 1.1 -> 1,10 0.1 -> 0,10 What I have tried: String test1 = NumberFormat.getInstance().format(1.1); // -> 1,1 String test2 = NumberFormat.getCurrencyInstance().format(1.1); // -> 1,10 € How could I get the same format as the second example, without the currency symbol? Or alternativly, how could I make sure the result from the

Converting Numbers into Words

情到浓时终转凉″ 提交于 2020-05-14 02:27:51
问题 I have taken this code from Stackoverflow and modified it, but i am unable to convert number for more than 3 digits. Here is the code: var num = this.rawValue; var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ', 'thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen ']; var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety']; var c = ['thousand', 'million', '']; num = num

Format a number to two decimal places

时光毁灭记忆、已成空白 提交于 2020-05-10 07:29:49
问题 Give me a native (no jQuery, Prototype, etc. please) JavaScript function that converts numbers as follows: input: 0.39, 2.5, 4.25, 5.5, 6.75, 7.75, 8.5 output: 0.39, 2.50, 4.25, 5.50, 6.75, 7.75, 8.50 E.g., in Ruby, I'd do something like this: >> sprintf("%.2f", 2.5) => "2.50" The output may be a number or a string. I don't really care because I'm just using it to set innerHTML . Thank you. 回答1: input = 0.3; output = input.toFixed(2); //output: 0.30 回答2: You can use the toFixed() method on