numbers

Store and perform operations with huge numbers in iOS

﹥>﹥吖頭↗ 提交于 2019-11-28 05:28:41
问题 How could I handle operations with a number like: 48534588306961133067968196965257961415756656521818848750723547477673457670019632882524164647651492025728980571833579341743988603191694784406703 Nothing that I've tried worked so far... unsigned long, long long, etc... 回答1: What you need is a library that provides support for operations on integers of arbitrary length. However, from what I've been able to find out, there are no such libraries written in Objective-C. You are nevertheless in luck

Remove/ truncate leading zeros by javascript/jquery

橙三吉。 提交于 2019-11-28 05:10:47
Suggest solution for removing or truncating leading zeros from number(any string) by javascript,jquery. You can use a regular expression that matches zeroes at the beginning of the string: s = s.replace(/^0+/, ''); I would use the Number() function: var str = "00001"; str = Number(str).toString(); >> "1" Or I would multiply my string by 1 var str = "00000000002346301625363"; str = (str * 1).toString(); >> "2346301625363" Maybe a little late, but I want to add my 2 cents. if your string ALWAYS represents a number, with possible leading zeros, you can simply cast the string to a number by using

How can I randomize numbers in an array [duplicate]

只愿长相守 提交于 2019-11-28 04:52:32
问题 This question already has answers here : Most efficient way to randomly “sort” (Shuffle) a list of integers in C# (13 answers) Closed 4 years ago . I have an array like this one: int[] numbers = new [] { 1, 2, 3, 4 }; I'd like to randomize this (different each time) so that it makes another array with the same size and numbers but in a different order each time. 回答1: Try something like this: System.Random rnd = new System.Random(); var numbers = Enumerable.Range(1, 4).OrderBy(r => rnd.Next())

String to Int in java - Likely bad data, need to avoid exceptions

橙三吉。 提交于 2019-11-28 04:20:52
Seeing as Java doesn't have nullable types, nor does it have a TryParse(), how do you handle input validation without throwing an exceptions? The usual way: String userdata = /*value from gui*/ int val; try { val = Integer.parseInt(userdata); } catch (NumberFormatException nfe) { // bad data - set to sentinel val = Integer.MIN_VALUE; } I could use a regex to check if it's parseable, but that seems like a lot of overhead as well. What's the best practice for handling this situation? EDIT: Rationale: There's been a lot of talk on SO about exception handling, and the general attitude is that

Why variable can not start with a Number?

蹲街弑〆低调 提交于 2019-11-28 04:13:01
问题 I am working in PHP, I have to define variables in sequence to save in Mysql. Both field name and variable name must be same in my case. Can I declare a variable like this $1 OR $2 etc If not why not and if yes why yes? I tried: $id = 0; $6 = $_REQUEST['6']; $7 = $_REQUEST['7']; $8 = $_REQUEST['8']; $xary = array('6','7','8','9') $oAppl->save_record("tablename", $id, "id"); which give me error. Also can I create and use fields in Mysql with the same name? 回答1: This is how PHP was designed.

How to customize JSF conversion message 'must be a number consisting of one or more digits'?

百般思念 提交于 2019-11-28 04:12:01
问题 I have an input text that is mapped to a Long property. private Long length; <h:inputText value="#{bean.length}" /> When I enter non-digits in that input text, I get the following conversion error: myForm:myField: 'someText' must be a number consisting of one or more digits. I was wondering how to customize this message to: length must be a number greater than zero. 回答1: Either use the input component's converterMessage attribute: <h:inputText converterMessage="length must be a number greater

php random x digit number

浪尽此生 提交于 2019-11-28 03:54:06
I need to create a random number with x amount of digits. So lets say x is 5, I need a number to be eg. 35562 If x is 3, then it would throw back something like; 463 Could someone show me how this is done? You can use rand() together with pow() to make this happen: $digits = 3; echo rand(pow(10, $digits-1), pow(10, $digits)-1); This will output a number between 100 and 999. This because 10^2 = 100 and 10^3 = 1000 and then you need to subtract it with one to get it in the desired range. If 005 also is a valid example you'd use the following code to pad it with leading zeros: $digits = 3; echo

Create a unique number with javascript time

↘锁芯ラ 提交于 2019-11-28 03:52:55
I need to generate unique id numbers on the fly using javascript. In the past, I've done this by creating a number using time. The number would be made up of the four digit year, two digit month, two digit day, two digit hour, two digit minute, two digit second, and three digit millisecond. So it would look something like this: 20111104103912732 ... this would give enough certainty of a unique number for my purposes. It's been a while since I've done this and I don't have the code anymore. Anyone have the code to do this, or have a better suggestion for generating a unique ID? If you just want

How to set locale for numbers in angular 2.0

孤街醉人 提交于 2019-11-28 03:52:09
问题 The number format in Swiss German is like "100'000.00" (not "100,000.00"). How can I change that? I tried to change the settings in number_pipe.js from en-US to de-CH without success. var defaultLocale: string = 'de-CH'; Is there a workaround or do I have to implement my own pipe? 回答1: Try using the locale-number.pipe.ts or you could create a simple pipe based on NumeralJs to format numbers https://github.com/adamwdraper/Numeral-js 回答2: If you only need one locale for your app, you can as of

Java - Format number to print decimal portion only

跟風遠走 提交于 2019-11-28 03:44:41
问题 Is there a simple way in Java to format a decimal, float, double, etc to ONLY print the decimal portion of the number? I do not need the integer portion, even/especially if it is zero! I am currently using the String.indexOf(".") method combined with the String.substring() method to pick off the portion of the number on the right side of the decimal. Is there a cleaner way to do this? Couldn't find anything in the DecimalFormat class or the printf method. Both always return a zero before the