double

Convert float value to string

主宰稳场 提交于 2019-12-11 23:27:30
问题 I have a property like this: public float Lat{ get { float lat; if (!float.TryParse(hdnLat.Value, out lat)) { throw new NotImplementedException(); } return lat; } set { hdnLat.Value = value; // Line 43 } } I got Latitude and Longitude from Google Maps and i get the cordinates from two asp.net hiddenfields. <asp:HiddenField ID="hdnLat" runat="server" /> <asp:HiddenField ID="hdnLng" runat="server" /> I store my latitude and longitude as float in my databas so i have to convert it to float right

Java Double/Integer

孤人 提交于 2019-12-11 23:22:52
问题 int a = 1; int b = 10; int c = 3; int d = (1/10)*3 System.out.println(d) Result: 0 How do i make this Calculation work ? and round up or down ? It should be: (1/10)*3 = 0.1 * 3 = 0.3 = 0 and (4/10)*3 = 0.4 * 3 = 1.2 = 1 Thanks a lot! 回答1: 1 / 10 This is integer division and as integer division the result is 0. Then 0 * 3 = 0 You can use double literals: 1.0 / 10.0 回答2: Try: int d = (int) (((double)4/10)*3); 回答3: 1/10 This line return 0.so 0*3=0.Use double instead of int 回答4: as both a and b

conversion error in c program from s64 to double?

旧时模样 提交于 2019-12-11 21:25:47
问题 In kernel : I am reading the time value as type extern s64 Latency; In user space : extern double latency; //fp is reading the kernel value (i.e Latency) fscanf (fp,"%lf", latency); If I read s64 from kernel as double in the user space. Is there possibility of data loss ?? which data type should I use to get the complete value ?? 回答1: The short answer: Yes, there will definitely be data loss. Think about it, both a signed 64 bit integer ( s64 ) and a double has 64 bits of storage. But whereas

Reading double matrix from cin

假如想象 提交于 2019-12-11 20:21:14
问题 I need to read squad matrix from cin, but I don't know the size of this matrix. So I need to read first row(double numbers separated by space or tab till end of line). After parse this line to get count of double numbers. If in row will be n double numbers then matrix size will nxn. How can I do that? Code: unsigned int tempSize = 0; double tempPoint; double * tempArray = new double [0]; string ts; getline(std::cin, ts); std::istringstream s(ts); while (s >> tempPoint){ if (!s.good()){ return

Detect scanner input in java (double or int)

最后都变了- 提交于 2019-12-11 20:09:31
问题 I was trying to do this: import java.util.Scanner; public class Prov{ public static void main(){ Scanner getInfo = new Scanner(System.in); showInfo(getInfo.next()); } public void showInfo(int numb){ System.out.println("You typed this integer: " + numb); } public void showInfo(double numb){ System.out.println("You typed this double: " + numb); } } but it doesnt work no matter if I look for scanner.next or scanner.nextInt it wont just get a double when i write a double and an int when I type an

Objective-C - Get number of decimals of a double variable

自古美人都是妖i 提交于 2019-12-11 19:56:55
问题 Is there a nice way to get the number of decimals of a double variable in Objective-C? I am struggling for a while to find a way but with no success. For example 231.44232000 should return 5. Thanks in advance. 回答1: You could, in a loop, multiply by 10 until the fractional part (returned by modf()) is really close to zero. The number of iterations'll be the answer you're after. Something like: int countDigits(double num) { int rv = 0; const double insignificantDigit = 8; double intpart,

Generate random doubles in between a range of values - Java

流过昼夜 提交于 2019-12-11 19:35:34
问题 I have written this piece of code which generates random doubles in between -1 and 1. The only problem is that it only produces one random double and then just prints out that for the other doubles that I want to produce. E.g. if the first double is 0.51 it just prints 0.51 over and over again instead of generating new random doubles. What is wrong with the following code? public static void main(String[] args) { double start = -1; double end = 1; double random = new Random().nextDouble();

How do I stop at a particular point in a file *stream and scan in some values?

笑着哭i 提交于 2019-12-11 17:47:52
问题 I have a file called test.txt the file contains: <this is a test = 1> <more tests = 42 and more "34"> <start>10.213123 41.21231 23.15323</start> <random stuff = "4"> <blah 234> When I see <start> I want to scan in the 3 numbers after into a double like this: x = 10.213123 y = 41.21231 z = 23.15323 I'm sort of confused because here, fgets scans the entire line, how can I scan in the 3 numbers into a double? Because the numbers can be of various lengths? I made this to print out what it reads

Doubleword-length 2’s complement representation of Binary number?

雨燕双飞 提交于 2019-12-11 17:13:44
问题 Doing my first assignment in Assembler and this is the question posed... 1.Find the doubleword-length 2’s complement representation of each of the following decimal numbers. (Steps of getting your results must be displayed, otherwise you get zero point.) a -100 b -55555 I have a very foreign professor that I completely can't understand so I'm in need of some assistance. So a doubleword would be 32 bits which would make... A) 0000|0000|0000|0000|0000|0001|0000|0000 ( 1 at beginning for

C's float and double precision? [duplicate]

蓝咒 提交于 2019-12-11 16:56:53
问题 This question already has answers here : 'float' vs. 'double' precision (6 answers) Is floating point math broken? (31 answers) Closed last year . I recently found this C code online. #include <stdio.h> int main() { double x = 3.1; float y = 3.1; if(x==y) printf("yes"); else printf("No"); } The output is No . I added a few more printf calls to investigate #include <stdio.h> int main() { double x = 3.1; float y = 3.1; if(x==y) printf("yes"); else printf("No"); printf("%.10f\n", y); printf("%