Results 1 to 2 of 2
Thread: Random .000000000X's
- 09-16-2011, 10:47 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
Random .000000000X's
Alright so this program is suppose to make a chart converting Celsius to Farenheit, what I dont understand is why there are .000000X's after some of the numbers, any ideas?
public class CelsiusFarenheitCalculator
{
public static void main(String[] args)
{
int C; //Celsius Value
int aF; //Approximate Farenheit Value
double F; //Farenheit Value
System.out.print("Celsius\t Farenheit\t Approximate Farenheit");
for(C=0;C<=100;C++)
{
aF = 2*C + 32;
F = 1.8*C +32;
System.out.println("\n "+C+"\t\t"+F+"\t\t "+aF);
}
}
OUTPUT
Celsius Farenheit Approximate Farenheit
0 32.0 32
1 33.8 34
2 35.6 36
3 37.4 38
4 39.2 40
5 41.0 42
6 42.8 44
7 44.6 46
8 46.4 48
9 48.2 50
10 50.0 52
11 51.8 54
12 53.6 56
13 55.400000000000006 58
14 57.2 60
15 59.0 62
16 60.8 64
17 62.6 66
18 64.4 68
19 66.2 70
20 68.0 72
21 69.80000000000001 74
22 71.6 76
23 73.4 78
24 75.2 80
25 77.0 82
26 78.80000000000001 84
27 80.6 86
28 82.4 88
29 84.2 90
30 86.0 92
31 87.80000000000001 94
32 89.6 96
33 91.4 98
34 93.2 100
35 95.0 102
36 96.8 104
37 98.60000000000001 106
38 100.4 108
39 102.2 110
40 104.0 112
41 105.8 114
42 107.60000000000001 116
43 109.4 118
44 111.2 120
45 113.0 122
46 114.8 124
47 116.60000000000001 126
48 118.4 128
49 120.2 130
50 122.0 132
51 123.8 134
52 125.60000000000001 136
53 127.4 138
54 129.2 140
55 131.0 142
56 132.8 144
57 134.60000000000002 146
58 136.4 148
59 138.2 150
60 140.0 152
61 141.8 154
62 143.60000000000002 156
63 145.4 158
64 147.2 160
65 149.0 162
66 150.8 164
67 152.60000000000002 166
68 154.4 168
69 156.2 170
70 158.0 172
71 159.8 174
72 161.6 176
73 163.4 178
74 165.20000000000002 180
75 167.0 182
76 168.8 184
77 170.6 186
78 172.4 188
79 174.20000000000002 190
80 176.0 192
81 177.8 194
82 179.6 196
83 181.4 198
84 183.20000000000002 200
85 185.0 202
86 186.8 204
87 188.6 206
88 190.4 208
89 192.20000000000002 210
90 194.0 212
91 195.8 214
92 197.6 216
93 199.4 218
94 201.20000000000002 220
95 203.0 222
96 204.8 224
97 206.6 226
98 208.4 228
99 210.20000000000002 230
100 212.0 232
-
Re: Random .000000000X's
Please read this: What every Computer Scientist Should Know about Floating Point Numbers
The solution is to format the number String prior to displaying it, and to do this, you can use String.format(...) or DecimalFormat, or System.out.printf(...), your choice.
Similar Threads
-
Random Generation Not being random
By Mmarzex in forum New To JavaReplies: 8Last Post: 08-04-2011, 10:53 PM -
how i use the random class to random the cards i have
By yanipao in forum New To JavaReplies: 14Last Post: 10-19-2009, 10:57 AM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
Using Random
By razmyasdfg in forum CLDC and MIDPReplies: 1Last Post: 07-27-2008, 10:47 PM -
random numbers without random class`
By carlos123 in forum New To JavaReplies: 4Last Post: 01-17-2008, 10:44 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks