digits

TCPDF/PHP & Fonts: Uppercase Numbers (Descent numbers? Old style?)

核能气质少年 提交于 2019-12-10 22:39:15
问题 I'm given a special font with numbers like that: As you can see on the 3 for example, some numbers descent below the baseline. What I like to achieve is, that these numbers don't go below the line and that it looks like this: In Word this can be easily set in the character settings for the same font. How can one render digits in TCPDF like this? I'm totally stuck there and have no clue how to proceed. Cheers for any help! 回答1: It can be done, but it's messy... In principle you'll have to do

How do I square a number's digits?

雨燕双飞 提交于 2019-12-10 12:13:34
问题 How do I square a number's digits? e.g.: square(21){}; should result in 41 instead of 441 回答1: function sq(n){ var nos = (n + '').split(''); var res=""; for(i in nos){ res+= parseInt(nos[i]) * parseInt(nos[i]); } return parseInt(res); } var result = sq(21); alert(result) 回答2: This is easily done with simple math. No need for the overhead of string processing. var result = []; var n = 21; while (n > 0) { result.push(n%10 * n%10); n = Math.floor(n/10); } document.body.textContent = result

Fastest way to find the largest power of 10 smaller than x

独自空忆成欢 提交于 2019-12-09 11:35:18
问题 Is there any fast way to find the largest power of 10 smaller than a given number? I'm using this algorithm, at the moment, but something inside myself dies anytime I see it: 10**( int( math.log10(x) ) ) # python pow( 10, (int) log10(x) ) // C I could implement simple log10 and pow functions for my problems with one loop each, but still I'm wondering if there is some bit magic for decimal numbers. 回答1: An alternative algorithm is: i = 1; while((i * 10) < x) i *= 10; 回答2: Log and power are

Sum of digits in a string

旧巷老猫 提交于 2019-12-08 22:29:17
问题 if i just read my sum_digits function here, it makes sense in my head but it seems to be producing wrong results. Any tip? def is_a_digit(s): ''' (str) -> bool Precondition: len(s) == 1 Return True iff s is a string containing a single digit character (between '0' and '9' inclusive). >>> is_a_digit('7') True >>> is_a_digit('b') False ''' return '0' <= s and s <= '9' def sum_digits(digit): b = 0 for a in digit: if is_a_digit(a) == True: b = int(a) b += 1 return b For the function sum_digits ,

PHP Leftmost digit

懵懂的女人 提交于 2019-12-08 20:21:10
问题 let's say I have a variable containing an integer or a float (since integers might overflow into a float in PHP). I want to run some operation to get the leftmost digit and the rest of the remaining digits. To explain better: <?php $x = NULL; //this will hold first digit $num = 12345; //int /// run operation //outputs //$x = 1; //$num = 2345; var_dump($x, $num); ?> Now, I know there's multitudes of ways to do this if you represent the number as a string, but I'm trying to avoid type casting

Turkish Identity Number Verification in Swift

那年仲夏 提交于 2019-12-07 22:41:16
问题 How can I make sure that the given text is Turkish Identity Number? I have seen js version here and phthon version here Turkish Identity Verification is not checks only if its numeric, it has some other functions too. Let me be more clear, It is numeric and has 11 digits. For example Let assume that first 9 digits are represented by d, and the last ones represented by c: Identity Number = d1 d2 d3 d4 d5 d6 d7 d8 d9 c1 c2 10th digit must be, c1 = ( (d1 + d3 + d5 + d7 + d9) * 7 - (d2 + d4 + d6

How to Segment handwritten and printed digit without losing information in opencv?

本小妞迷上赌 提交于 2019-12-07 18:17:03
问题 I've written an algorithm that would detect printed and handwritten digit and segment it but while removing outer rectangle handwritten digit is lost using clear_border from ski-image package. Any suggestion to prevent information. Sample: How to get all 5 characters separately? 回答1: Segmenting characters from the image - Approach - Threshold the image (Convert it to BW) Perform Dilation Check the contours are large enough Find rectangular Contours Take ROI and save the characters Python Code

How can you get the number of digits contained in a double?

半腔热情 提交于 2019-12-07 15:34:43
问题 I'm trying to get the number of digits in the following double value: 56.46855976 without using converting it to a string (and simply replacing the "." with a ""). Anybody got any ideas? 回答1: Count how often you must divide the number by 10 until it's smaller than 1 -> that gives you the digits before the decimal point. Then count how often you must multiply the original number by 10 until it equals the Math.Floor-result -> that gives you the digits behind the decimal points. Add. Be glad.

Fastest way to sum digits in a number

*爱你&永不变心* 提交于 2019-12-07 14:28:07
问题 Given a large number, e.g. 9223372036854775807 ( Int64.MaxValue ), what is the quickest way to sum the digits? Currently I am ToStringing and reparsing each char into an int : num.ToString().Sum(c => int.Parse(new String(new char[] { c }))); Which is surely horrifically inefficent. Any suggestions? And finally, how would you make this work with BigInteger ? Thanks 回答1: Well, another option is: int sum = 0; while (value != 0) { int remainder; value = Math.DivRem(value, 10, out remainder); sum

Problem on getting digits in a double variable

巧了我就是萌 提交于 2019-12-07 08:23:53
问题 I got a little problem with a function I need in my java progam. I want to check the total amount of digits, a 'double' variable has. (e.g.: 5 should return 1, 5.0034 should return 5, and 2.04 should return 3.) My function is this: private int getDoubleLength (double a) { int len = 0; while (a != (int) a) { a *= 10; } while (a > 1) { len ++; a/=10; } System.out.println(String.format("Double %f has %d digits.",a,len)); return len; } Now this works perfectly, but when I am making some