numbers

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

Java and generics. Isn't 0 a Number?

只谈情不闲聊 提交于 2020-06-25 09:13:29
问题 What is that I'm missing about this snippet of code? public class Zero<N extends Number> { public N zero() { return new Integer(0); } } It says: Type mismatch: cannot convert from Integer to N Thanks! Update I've changed the snippet to use an integer. Same thing happens. And it happens even when creating an anonymous subclass of Number . Could it be Eclipse that is faulty about this? 回答1: While an Integer is a Number, an Integer might not be compatible to N which can be any subclass of Number

How to print out a numbered list in Python 3

故事扮演 提交于 2020-06-25 06:44:13
问题 How do I print out the index location of each of a python list so that it starts at 1, rather than 0. Here's an idea of what I want it to look like: blob = ["a", "b", "c", "d", "e", "f"] for i in blob: print(???) Output: 1 a 2 b 3 c 4 d 5 e What I need to know is how do I get those numbers to show up alongside what I'm trying to print out? I can get a-e printed out no problem, but I can't figure out how to number the list. 回答1: for a, b in enumerate(blob, 1): print '{} {}'.format(a, b) 回答2:

Extract all numbers from string

大憨熊 提交于 2020-06-23 12:18:26
问题 Let's say I have a string such as 123ad456 . I want to make a method that separates the groups of numbers into a list, so then the output will be something like 123,456 . I've tried doing return Regex.Match(str, @"-?\d+").Value; , but that only outputs the first occurrence of a number, so the output would be 123 . I also know I can use Regex.Matches , but from my understanding, that would output 123456 , not separating the different groups of numbers. I also see from this page on MSDN that

Extract all numbers from string

99封情书 提交于 2020-06-23 12:15:13
问题 Let's say I have a string such as 123ad456 . I want to make a method that separates the groups of numbers into a list, so then the output will be something like 123,456 . I've tried doing return Regex.Match(str, @"-?\d+").Value; , but that only outputs the first occurrence of a number, so the output would be 123 . I also know I can use Regex.Matches , but from my understanding, that would output 123456 , not separating the different groups of numbers. I also see from this page on MSDN that

Python - Pymongo MongoDB 3.4 - NumberDecimal

好久不见. 提交于 2020-06-18 09:07:13
问题 i am using mongodb 3.4 in order to insert proper prices to my database.. According to: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#reading-from-extended-json i used this in my python code: 'credits': {'$numberDecimal': Decimal128('9.99')}, but throws: bson.errors.InvalidDocument: key '$numberDecimal' must not start with '$' So what is the correct syntax for inserting numberdecimal in mongodb using python ? thanks and greetings 回答1: Simply this:

Group PHP array numbers

六月ゝ 毕业季﹏ 提交于 2020-06-12 06:23:57
问题 How I can change this: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 11 [8] => 21 [9] => 22 [10] => 23 [11] => 24 ) To this: 1-7, 11, 21-24 I have a list of numbers like this in PHP array, and I just want to make this list a little bit smaller. 2000: 3 6 7 11 15 17 25 36 42 43 45 2001: 2 3 4 5 6 9 10 11 12 13 34 37 45 46 47 48 49 50 51 52 2002: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 39 40 41 42 43 44

Regex to accept numbers and/or number range separated by commas, but between range 1-4093

耗尽温柔 提交于 2020-06-09 07:10:30
问题 I need a regex to validate VLAN string entered by user. The string should allow numbers or ranges, separated by comma. The numbers must be between 1 and 4093. Below samples are allowed: 1, 1,2,3,4 1-10, 1-4093 4000 I tried below : ^0*([1-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-3][0-9]{3}|40[0-8][0-9]|409[0-3])$ Need to enhance for comma separated and ranges 回答1: To match a number from 1 to 4093 one can use: (?:[1-9]\d{0,2}|[1-3]\d{3}|40(?:[0-8]\d|9[0-3])) That we'll call N .

Why char is not taken as numeral in C++?

北慕城南 提交于 2020-06-08 19:45:30
问题 I wrote a code in C, which ran perfectly, I translated it to C++ . There it was giving wrong output. I had an iteration where I used both the input and the iterator variable as char to save space. But didn't behaved as expected. unsigned char repeat, i; cin >> repeat; for(i= 0; i < repeat; i++) What is the equivalent line for scanf("%hhi", &repeat) ? 回答1: Why char is not taken as numeral in C++? Because C and C++ are different programming languages. See for example n3337, a draft C++ standard