numbers

Format string to a 3 digit number

左心房为你撑大大i 提交于 2019-11-28 22:16:40
Instead of doing this, I want to make use of string.format() to accomplish the same result: if (myString.Length < 3) { myString = "00" + 3; } If you're just formatting a number, you can just provide the proper custom numeric format to make it a 3 digit string directly: myString = 3.ToString("000"); Or, alternatively, use the standard D format string : myString = 3.ToString("D3"); Haitham Salem string.Format("{0:000}", myString); It's called Padding : myString.PadLeft(3, '0') (Can't comment yet with enough reputation , let me add a sidenote) Just in case your output need to be fixed length of 3

Read numbers from the console given in a single line, separated by a space

一世执手 提交于 2019-11-28 21:35:51
I have a task to read n given numbers in a single line, separated by a space from the console. I know how to do it when I read every number on a separate line ( Console.ReadLine() ) but I need help with how to do it when the numbers are on the same line. You can use String.Split . You can provide the character(s) that you want to use to split the string into multiple. If you provide none all white-spaces are assumed as split-characters(so new-line, tab etc): string[] tokens = line.Split(); // all spaces, tab- and newline characters are used or, if you want to use only spaces as delimiter:

What exactly does Double mean in java?

妖精的绣舞 提交于 2019-11-28 21:17:45
I'm extremely new to Java and just wanted to confirm what Double is? Is it similar to Float or Int? Any help would be appreciated. I also sometimes see the uppercase Double and other times the lower case double . If someone could clarify what this means that'd be great! sgokhales Double is a wrapper class, The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and

What is the maximum value of a number in Lua?

こ雲淡風輕ζ 提交于 2019-11-28 20:32:02
There doesn't seem to be a clear answer to this in the documentation. I'm interested in incrementing a variable time that counts the seconds since the program started. If the maximum value can count far into the future, like 100 years, then I don't care about letting the variable increment forever. Otherwise I'm going to have to think of a good point to reset time back to 0. as compiled by default, the Number is a double , on most compilers that's an IEEE 64-bit floating point. that means 10bit exponent, so the maximum number is roughly 2^1024, or 5.6e300 years. that's a long time. now, if you

How to format a number 1000 as “1 000”

丶灬走出姿态 提交于 2019-11-28 20:13:56
I need a way to format numbers. I stored some numbers in my DB table, e.g. 12500 , and would like to print them in this format 12 500 (so there is a space every 3 digits). Is there an elegant way to do this? see: http://www.justskins.com/forums/format-number-with-comma-37369.html there is no built in way to it ( unless you using Rails, ActiveSupport Does have methods to do this) but you can use a Regex like formatted_n = n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse Activesupport uses this regexp (and no reverse reverse). 10000000.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1 ") #=> "10 000 000"

Styling HTML5 input type number

一世执手 提交于 2019-11-28 20:06:14
I'm writing a form in HTML5. One of the inputs is type=number . I want the input to only show 2 digits but it seems to default to showing at least 5 digits, which takes up extra space. I've tried adding size="2" attribute, with no effect. This the tag i'm using: <input type="number" name="numericInput" size="2" min="0" max="18" value="0" /> What am I missing? HTML5 number input doesn't have styles attributes like width or size, but you can style it easily with CSS. input[type="number"] { width:50px; } user3464091 I have been looking for the same solution and this worked for me...add an inline

PHP: intval() equivalent for numbers >= 2147483647

余生颓废 提交于 2019-11-28 20:02:26
问题 In PHP 5, I use intval() whenever I get numbers as an input. This way, I want to ensure that I get no strings or floating numbers. My input numbers should all be in whole numbers. But when I get numbers >= 2147483647, the signed integer limit is crossed. What can I do to have an intval() equivalent for numbers in all sizes? Here's what I want to have: <?php $inputNumber = 3147483647.37; $intNumber = intvalEquivalent($inputNumber); echo $intNumber; // output: 3147483647 ?> Thank you very much

Javascript - validation, numbers only

为君一笑 提交于 2019-11-28 18:39:38
I'm trying to get my login form to only validate if only numbers were inputted. I can it to work if the input is only digits, but when i type any characters after a number, it will still validate etc. 12akf will work. 1am will work. How can i get past this? Part of the Login <form name="myForm"> <label for="firstname">Age: </label> <input name="num" type="text" id="username" size="1"> <input type="submit" value="Login" onclick="return validateForm()"> function validateForm() { var z = document.forms["myForm"]["num"].value; if(!z.match(/^\d+/)) { alert("Please only enter numeric characters only

find the number of strings in an array of strings in C

守給你的承諾、 提交于 2019-11-28 18:38:17
char* names[]={"A", "B", "C"}; Is there a way to find the number of strings in the array. Like, for example in this case, it has to be 3. Please let me know. Thanks. In this case you can divide the total size by the size of the first element: num = sizeof(names) / sizeof(names[0]); Careful though, this works with arrays . It won't work with pointers. For an array, which the examples in the bounty are, doing sizeof(names)/sizeof(names[0]) is sufficient to determine the length of the array. The fact that the strings in the examples are of different length does not matter. names is an array of

Computing target number from numbers in a set

*爱你&永不变心* 提交于 2019-11-28 18:21:28
I'm working on a homework problem that asks me this: Tiven a finite set of numbers, and a target number, find if the set can be used to calculate the target number using basic math operations (add, sub, mult, div) and using each number in the set exactly once (so I need to exhaust the set). This has to be done with recursion. So, for example, if I have the set {1, 2, 3, 4} and target 10, then I could get to it by using ((3 * 4) - 2)/1 = 10. I'm trying to phrase the algorithm in pseudo-code, but so far haven't gotten too far. I'm thinking graphs are the way to go, but would definitely