numbers

having a constant decrease of a number when pushing a button in C#

落爺英雄遲暮 提交于 2019-12-10 17:44:20
问题 I am a begginer, so make it easy for me. I want to display an collection of images at in order of their name (0-20) when I press a button . I managed to do it with a random number (0-20), but if I want to have a decrease from 20 to 19 to 18 and so on, how would I do that? public partial class Form1 : Form { //Random r = new Random(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string path = @"C:\Users\Ole-Jeger\Documents\Visual Studio

How can I write a fast function to calculate total divisors of a number?

巧了我就是萌 提交于 2019-12-10 17:38:58
问题 I have to find the the total number of divisors of a given number N where can be as large as 10^14 .I tried out calculating the primes upto 10^7 and then finding the the divisors using the exponents of the prime factors.However it is turning out to be too slow as finding the primes using the sieve takes 0.03 s. How can I calculate the total number of divisors faster and if possible without calculating the primes? Please pseudo code /well explained algorithm will be greatly appreciated. 回答1:

Represent 9999999999999999 in actionscript 3

无人久伴 提交于 2019-12-10 17:33:33
问题 I tried storing 10 16 - 1 in a Number variable: var n:Number = 9999999999999999 but the value stored in n ends up being 10000000000000000, or 10 17 . How can I represent 10 16 - 1 in actionscript 3? 回答1: You've ran out of Number type precision capability, so you'll have to devise your own way to store numbers this big with the required precision. One of the most common way to operate long arithmetic is using strings as data holders, another is using a vector of ints, each position

Floating point precision in literals vs calculations

房东的猫 提交于 2019-12-10 17:31:10
问题 I'm wondering why floating point numbers in Java can represent exact value when they are initialized as literals, but they are approximate when they represent result of some calculation. For example: double num1 = 0.3; double num2 = 0.1 + 0.2; System.out.println(num1); System.out.println(num2); why the result is: 0.3 0.30000000000000004 and not: 0.30000000000000004 0.30000000000000004 When there is no exact binary representation of 0.3. I know the BigDecimal class, but I don't quite

Why should I not use deprecated align='right' for numbers on an TD (table cell)?

回眸只為那壹抹淺笑 提交于 2019-12-10 17:24:14
问题 I am referring to the usage a table for showing tabular data, eg: a spreadsheet, focusing on numbers , that I feel and see in UX that should be right aligned, properly formatted (with same number of decimals) to facilitate sums. For numbers this looks like a borderline case between semantics and formatting, for other kind of data types like dates choosing an alignment is more arbitrary. I of course agree in using css when possible but css is not always supported or enabled and I see reasons

How did a float turn into a double here?

笑着哭i 提交于 2019-12-10 15:14:46
问题 Edit: As always, great answer in under 5 minutes :) Turns out if I make a tiny change - make the F capital in "float", I'll get the output I expected. class NumberMachine{ public static void main(String [] args) { Integer wi1 = new Integer("420"); int i = 101; Integer wi2 = i*420/101; if(wi1 == wi2) System.out.print(" =="); if(wi1.equals(wi2)) System.out.print(" equal"); float f = 1.23f; //if this were Float f..., it'd print Float, not double. new NumberMachine().printIt(f); } void printIt

How to make JavaFX Chart NumberAxis only show Integer value,not double

独自空忆成欢 提交于 2019-12-10 15:10:57
问题 I'm trying to create a chart who's yAxis is designed to show number of employee number, so it must only show whole numbers. But I found it's not that easy as I already tried to yAxis.setTickUnit(1) but it won't work when the values are small(etc. the max value is 3, it'll still show 0.5,1.5..., I only want tick value like 1,2,3,4..) How Could I to achieve this? According to @jewelsea 's answer, I tried this(In javafx 2.2 jdk7) class IntegerStringConverter extends StringConverter<Number>{

Finding the nth occurrence of a number using regex

蓝咒 提交于 2019-12-10 15:00:20
问题 I am trying to write a regex that can find the nth occurrence of a number match (where N is a number that can increment in a for loop). I can get the regex to successfully match a number, but I can't get it to match a specific number in the sequence. The regex I used is ([0-9]+){2} . What I am trying to do is pick out the number out of a string like: Red,12,Green,5,Blue,6 Using a regex that can pick out, 12 then, 2, then 3. I was hoping the {n} part of the regex could accomplish this, but

output to stream float numbers with precision

折月煮酒 提交于 2019-12-10 14:56:04
问题 I have a problem with float numbers precision: int main(void) { double b = 106.829599; float a = b; std::cerr << std::setprecision(6) << "a = " << a << "; b = " << b << std::endl; std::cerr << std::setprecision(7) << "a = " << a << "; b = " << b << std::endl; } result is: a = 106.83; b = 106.83 a = 106.8296; b = 106.8296 So, my question is why numbers in first line are so short (I was expecting to see 106.829) gcc 4.1.2, also I made a test at LWS 回答1: Actually, 106.829599 rounded to 6 digits

Parse a number but keep negative's

房东的猫 提交于 2019-12-10 14:31:46
问题 I am trying to un-format a number to it's original form but keep whether or not it is negative. Someone on stack overflow led me to this code that work's very nicely but it does not keep the negative. Could anyone help me get a better fix on this? EDIT - For USD Currency/normal numbers Example: 1,234 = 1234 -1,234 = -1234 1,234.00 = 1234 1,234.56 = 1234.56 function numberUnformat($number) { $cleanString = preg_replace('/([^0-9\.,])/i', '', $number); $onlyNumbersString = preg_replace('/([^0-9]