numbers

Check if string is number in android

爱⌒轻易说出口 提交于 2019-12-04 01:28:43
I have three text fields all which are numbers or a decimal number. They are accepted as strings which are later converted. However, i want to validate these fields so that only the numbers or decimal numbers are accepted. Whats the easiest way to ensure that these fields are only characters 0-9. I would prefer an if statement but any solution would be nice! Use string.matches method which accepts a regex as an argument. if(string.matches("\\d+(?:\\.\\d+)?")) { System.out.println("Matches"); } else { System.out.println("No Match"); } If you are inflating those textviews from xml you can just

java String.format: numbers with localization

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:33:41
Is it possible to localize numbers in String.format call the same way as NumberFormat.format does? I've expected it simply to use String.format(locale, "%d", number) but this doesn't return the same result as if using NumberFormat. For example: String.format(Locale.GERMAN, "%d", 1234567890) gives: "1234567890", while NumberFormat.getNumberInstance(Locale.GERMAN).format(1234567890) gives: "1.234.567.890" If it can't be done, what's recommended way for localizing text including numbers? From the documentation , you have to: supply a locale (as you are doing in your example) include the ',' flag

Split number into sum components

五迷三道 提交于 2019-12-03 23:20:55
Is there an efficient algorithm to split up a number into N subsections so that the sum of the numbers adds up to the original, with a base minimum? For example, if I want to split 50 into 7 subsections, and have a base minimum of 2, I could do 10,5,8,2,3,5,17 (as well as any other number of combinations). I'd like to keep the numbers as integers, and relatively random but I'm not sure how to efficiently generate numbers that sum up to the original and don't include numbers lower than the given minimum. Any suggestions? EDIT - Just to copy/paste my comment, the integers don't have to be unique

Numbers System in javascripts

空扰寡人 提交于 2019-12-03 22:28:29
Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a well- defined value, and the result of this operation is the special not-a-number value, printed as NaN . NaN also arises if you attempt to divide infinity by infinity, or take the square in JavaScript root of a negative number or use arithmetic operators with non-numeric operands that cannot be converted to numbers. for Example 1. 0===0 returns True & 1==1 returns true 2. 0/0 returns NaN & 1/1 returns 1 Zero is Number and one is

C++ Bessel function for complex numbers

无人久伴 提交于 2019-12-03 22:09:20
I want to implement the Bessel functions of first and second kind Description of bessel functions for complex numbers in C++. Now I am looking for possibilities to introduce them in my source code. Since math.h only contains bessel functions for real numbers, I would be interested in seeing any kind of possibility. The Boost library implements ordinary Bessel functions of the first and second kind and modified Bessel functions of the first and second kind for both real and complex numbers (see documentation about Bessel functions ). Don't try to reinvent the wheel , just use the Boost

Assembler 64b division

梦想的初衷 提交于 2019-12-03 20:19:42
I need some easy way to divide 64b unsigned integers in assembler for x86. My number is saved in two 32b registers EDX:EAX and I need to put result back to EDX:EAX. Factor is in 32b integer. Some code, please? If I interpret your question correctly (particularly the part Factor is in 32b integer ), you want to divide a 64-bit dividend by a 32-bit divisor and get a 64-bit quotient. If that interpretation is correct, then it's actually easy to do in 32-bit code. The idea is that you divide both "halves" of the dividend by the divisor and reuse the remainder from the first division for the second

Making use of sandy bridge's hardware true random number generator?

我怕爱的太早我们不能终老 提交于 2019-12-03 19:28:50
问题 I was wondering if there is a way to make use of the new hardware based true number generator found in intel's sandy bridge CPU? I read that intel's MKL (Math Kernel Library) exposes this functionality, but this requires the MKL suite and an intel complier, ending up pretty expensive. Is there another way to employ the hardware random number generator in my C++ code? For example a nice, header only library? 回答1: Intel has posted a manual, library, and code examples for the rdrand instruction

PHP check if variable is a whole number

隐身守侯 提交于 2019-12-03 19:17:07
问题 I have this PHP code: $entityElementCount = (-($highScore-$totalKeywordCount))/0.29; What i want to know is, how to check whether $entityElementCount is a whole number (2, 6, ...) or partial (2.33, 6.2, ...). Thank you! 回答1: $entityElementCount = (-($highScore-$totalKeywordCount))/0.29; if (ctype_digit($entityElementCount) ){ // (ctype_digit((string)$entityElementCount)) // as advised. print "whole number\n"; }else{ print "not whole number\n"; } 回答2: if (floor($number) == $number) 回答3: I know

Double multiplied by 100 and then cast to long is giving wrong value

时光怂恿深爱的人放手 提交于 2019-12-03 18:55:15
问题 I have the following code: Double i=17.31; long j=(long) (i*100); System.out.println(j); O/P : 1730 //Expected:1731 Double i=17.33; long j=(long) (i*100); System.out.println(j); O/P : 1732 //Expected:1733 Double i=17.32; long j=(long) (i*100); System.out.println(j); O/P : 1732 //Expected:1732{As expected} Double i=15.33; long j=(long) (i*100); System.out.println(j); O/P : 1533 //Expected:1533{as Expected} I have tried to Google but unable to find reason.I am sorry if the question is trivial.

Numbers to Roman Numbers with php

只谈情不闲聊 提交于 2019-12-03 18:48:15
问题 I need to transform ordinary numbers to Roman numerals with php and I have this code: <?php function roman2number($roman){ $conv = array( array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) ); $arabic = 0; $state = 0; $sidx = 0;