-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex.html
141 lines (137 loc) · 3.13 KB
/
ex.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<title>Feet to Meters Length Converter</title>
<body>
<h2>Length Converter</h2>
<p>This tool converts feet to meters while keeping in mind sig figs. I made it this for aid in converting measurements on my benchmarks section of the site.</p>
<p>Type a value in the Feet field to convert the value to Meters:</p>
<p>
<label>Feet</label>
<input id="inputFeet" type="number" placeholder="Feet" oninput="LengthConverter(this.value)" onchange="LengthConverter(this.value)">
</p>
<p>Meters: <span id="outputMeters"></span></p>
<p>
<label>Meters</label>
<input id="inputMeters" type="number" placeholder="Meters" oninput="LengthConverterM(this.value)" onchange="LengthConverterM(this.value)">
</p>
<p>Feet: <span id="outputFeet"></span></p>
<script>
function LengthConverter(valNum) {
let value = valNum / 3.28084
// Credit .lines 20-72 https://onecompiler.com/javascript/3wxpgxjhq tysm
const sigFigs = (n) => {
let a = 0;
let b = n.length;
let c = 0;
let d = 0;
let e = 0;
let f = 0;
let g = 0;
let h = 0;
let i = 0;
for (let i = 0; i < b; i++) {
if (n[i] == ".") {
d = 1;
}
}
if (d === 0) {
for (let i = 0; i < b; i++) {
if (n[i] != parseInt(n[i])) {
continue;
}
if (n[i] != 0) {
a += 1;
}
if (a > 0) {
c += 1
}
}
for (let i = b - 1; i > 0; i--) {
if (n[i] == 0) {
e += 1;
} else
if (n[i] != 0) {
break;
}
}
f = c - e;
return f;
} else
if (d !== 0 ) {
for (let i = 0; i < b; i++) {
if (n[i] != parseInt(n[i])) {
continue;
}
if (n[i] != 0) {
g += 1;
}
if (g > 0 && n[i] == 0) {
g += 1
}
}
return g;
}
};
document.getElementById("outputMeters").innerHTML=value.toPrecision(sigFigs(valNum));
}
function LengthConverterM(valNum) {
let value = valNum * 3.28084
// Credit .lines 20-72 https://onecompiler.com/javascript/3wxpgxjhq tysm
const sigFigs = (n) => {
let a = 0;
let b = n.length;
let c = 0;
let d = 0;
let e = 0;
let f = 0;
let g = 0;
let h = 0;
let i = 0;
for (let i = 0; i < b; i++) {
if (n[i] == ".") {
d = 1;
}
}
if (d === 0) {
for (let i = 0; i < b; i++) {
if (n[i] != parseInt(n[i])) {
continue;
}
if (n[i] != 0) {
a += 1;
}
if (a > 0) {
c += 1
}
}
for (let i = b - 1; i > 0; i--) {
if (n[i] == 0) {
e += 1;
} else
if (n[i] != 0) {
break;
}
}
f = c - e;
return f;
} else
if (d !== 0 ) {
for (let i = 0; i < b; i++) {
if (n[i] != parseInt(n[i])) {
continue;
}
if (n[i] != 0) {
g += 1;
}
if (g > 0 && n[i] == 0) {
g += 1
}
}
return g;
}
};
document.getElementById("outputFeet").innerHTML=value.toPrecision(sigFigs(valNum));
}
</script>
</body>
</html>