numbers

How do I format a double to a string and only show decimal digits when necessary?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 04:02:30
I have code like: lblFranshizShowInvwNoskhehEdit.Text = string.Format("{0:n}", (double)(int.Parse(drDarman["FranshizDarsad"].ToString()) * Convert.ToInt64(RadNumerictxtPayInvwNoskhehEdit.Text)) / 100); But {0:n0} string format forces the label's text to not have decimal digits and {0:n} string format forces the label's text to have 2 decimal digits (default). In my scenario I just want decimal digits when necessary / without rounding them / how can I do that? You can just do: string.Format("{0}", yourDouble); It will include only digits when necessary. If you want other examples of formatting

Bash Number Limit?

萝らか妹 提交于 2019-11-29 03:55:01
I asked a question earlier that involved pulling large primes from a text file and putting them into another file. It was supposed to grab every prime up to and including the first prime after 2^32, and for some reason this script stopped working. #!/bin/bash n=4294967296 last=0 while read number do if [ $last -gt $n ] then break fi echo $number last=$number done < primes.txt > primes2.txt It ended up looping through these 11 numbers: 4232004449 4232004479 4232004493 4232004509 4232004527 4232004533 4232004559 4232004589 4232004593 4232004613 004437 The original file didn't have 004437 in it,

SQL BETWEEN for text vs numeric values

此生再无相见时 提交于 2019-11-29 03:45:51
BETWEEN is used in a WHERE clause to select a range of data between two values. If I am correct whether the range's endpoint are excluded or not is DBMS specific. What I can not understand in the following: If I have a table of values and I do the following query: SELECT food_name FROM health_foods WHERE calories BETWEEN 33 AND 135;` The query returns as results rows including calories =33 and calories =135 (i.e. range endpoints are included ). But if I do: SELECT food_name FROM health_foods WHERE food_name BETWEEN 'G' AND 'O'; I do not get rows with food_name starting with O . I.e. the end of

Generating all distinct partitions of a number

早过忘川 提交于 2019-11-29 03:28:05
问题 I am trying to write a C code to generate all possible partitions (into 2 or more parts) with distinct elements of a given number. The sum of all the numbers of a given partition should be equal to the given number. For example, for input n = 6 , all possible partitions having 2 or more elements with distinct elements are: 1, 5 1, 2, 3 2, 4 I think a recursive approach should work, but I am unable to take care of the added constraint of distinct elements. A pseudo code or a sample code in C/C

Convert css width string to regular number

∥☆過路亽.° 提交于 2019-11-29 03:07:02
While trying to compute the width of an hidden element I found that jquery.width() returns 0 for that elements' width. I found out that using jquery.css('width') would return the correct width by using the declared style width (even if that value is different from the initial stylesheet). The problem is that the css('width') method returns a string, generally in a "100px" fashion. My question resolves into: how to retrieve the number from the "100px" string? Is there an easy way? Fenton If it always returns in px format, "100px", "50px" etc (i.e. not "em" or percent), you could just... var

Check if a string contains numbers

倖福魔咒の 提交于 2019-11-29 02:59:50
How do I check if a string in a MySQL field contains a number then delete them? Example table: tbl_tags ------------- | id | tag | ------------- | 1 | hello | | 2 | hello2 | | 3 | 2hello | | 4 | hel3lo | ------------- The only way I can think of is to do each number individually and use LIKE '%1%' OR LIKE '%2%' etc. But there must be an easier way? Check out the MySQL Regex methods . Something like the following should work. SELECT * FROM table WHERE tag REGEXP '[0-9]' user3200518 SELECT * FROM clients WHERE name REGEXP '^[[:digit:]]+$' ORDER BY `clients`.`country_id` DESC LIMIT 0 , 30 this is

C: how to break apart a multi digit number into separate variables?

为君一笑 提交于 2019-11-29 02:59:29
Say I have a multi-digit integer in C. I want to break it up into single-digit integers. 123 would turn into 1 , 2 , and 3 . How can I do this, especially if I don't know how many digits the integer has? int value = 123; while (value > 0) { int digit = value % 10; // do something with digit value /= 10; } First, count the digits: unsigned int count(unsigned int i) { unsigned int ret=1; while (i/=10) ret++; return ret; } Then, you can store them in an array: unsigned int num=123; //for example unsigned int dig=count(num); char arr[dig]; while (dig--) { arr[dig]=num%10; num/=10; } As a hint,

What's the deal with char.GetNumericValue?

喜夏-厌秋 提交于 2019-11-29 02:55:48
I was working on Project Euler 40 , and was a bit bothered that there was no int.Parse(char) . Not a big deal, but I did some asking around and someone suggested char.GetNumericValue . GetNumericValue seems like a very odd method to me: Takes in a char as a parameter and returns...a double? Returns -1.0 if the char is not '0' through '9' So what's the reasoning behind this method, and what purpose does returning a double serve? I even fired up Reflector and looked at InternalGetNumericValue, but it's just like watching Lost: every answer just leads to another question. Remember that it's

Fastest way to get number of digits on a number? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-11-29 02:54:55
问题 This question already has answers here : Way to get number of digits in an int? (28 answers) Closed 6 years ago . I have do detect the amount of digits on a number. For example, 329586 has 6 digits. What I done, is simply parsing the number to string, and getting the string length, like: number.toString().length() But, is there a fastest way to count digits on a number? I have to use this method several times, so I think using toString() can impact performance. Thanks. 回答1: Math.floor(Math

Octal equivalent in C#

安稳与你 提交于 2019-11-29 02:48:27
In C language Octal number can be written by placing 00 before number e.g. Editor's note: it is a single leading 0 that identifies a number literal as an octal value in C; additional 0 instances have no effect. int i=0012; //equals 10 in decimal I found the equivalent of Hexadecimal in C# by placing 0x before number e.g. int i=0xA; //equals 10 in decimal Now my question is: Is there any equivalent of Octal Number in C# like in C to represent any number as Octal? No, there are no octal number literals in C#. For strings: Convert.ToInt32("12", 8) returns 10 . No there isn't, the language