-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
167 lines (127 loc) · 5.07 KB
/
index.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Indian to international number system converter</title>
</head>
<style>
#inputFields {
width: 50%;
}
h3, label, input, button, p {
font-size: 1.2em;
}
h1 {
width: 50%;
}
.result {
font-size: 1.3em;
}
button {
margin: 10px;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
text-align: center;
font-size: 0.7em;
font-family: sans-serif;
width: 40%;
}
</style>
<body>
<h1>Indian to international numbering converter</h1>
<section id="inputFields">
<h3>Indian numbering system</h3>
<p><i>Enter value to be converted (with or without commas) in crores or lakhs field, then click on button to convert.</i></p>
<p><i>Values of crores and lakhs will be formatted into Indian number system.</i></p>
<label>Crore: <input type="text" id="crore" placeholder="number to convert"></label><button onclick="convertCrore()">Convert crore</button>
<br>
<label>Lakhs: <input type="text" id="lakhs" placeholder="number to convert"></label><button onclick="convertLakhs()">Convert lakhs</button>
<h3>International numbering system</h3>
<p><i>Converted values displayed below, in international format.</i></p>
<p>Converted from: <span class="result" id="originalNumber"></span></p>
<p>Thousands: <span class="result" id="thousands"></span></p>
<p>Millions: <span class="result" id="millions"></span></p>
<p>Billions: <span class="result" id="billions"></span></p>
<p>Tillions: <span class="result" id="trillions"></span></p>
</section>
<div class="footer">
<p>Created by <a href="http://www.richardcosgrove.co.uk/" rel="author" target="_blank" referrerpolicy="no-referrer">Richard Cosgrove</a> • GNU GPL v3.0 • June 2023 • <a href="https://github.com/rcosgrove/crore-converter" rel="author" target="_blank" referrerpolicy="no-referrer">Source code</a></p>
</div>
</body>
<script>
var croreAmount;
var lakhsAmount;
var thousandsAmount;
var millionsAmount;
var billionsAmount;
var trillionsAmount;
function getValues() {
// set variables to input values
croreAmount = document.getElementById('crore').value;
lakhsAmount = document.getElementById('lakhs').value;
// thousandsAmount = document.getElementById('thousands').value;
// millionsAmount = document.getElementById('millions').value;
// billionsAmount = document.getElementById('billions').value;
// trillionsAmount = document.getElementById('trillions').value;
}
function formatResults() {
// format numbers into Indian number format
croreAmount = new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(croreAmount);
lakhsAmount = new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(lakhsAmount);
// format numbers into UK number format
thousandsAmount = new Intl.NumberFormat('en-UK', { maximumSignificantDigits: 3 }).format(thousandsAmount);
millionsAmount = new Intl.NumberFormat('en-UK', { maximumSignificantDigits: 3 }).format(millionsAmount);
billionsAmount = new Intl.NumberFormat('en-UK', { maximumSignificantDigits: 3 }).format(billionsAmount);
trillionsAmount = new Intl.NumberFormat('en-UK', { maximumSignificantDigits: 3 }).format(trillionsAmount);
}
function writeResults() {
// write results to input and span fields
document.getElementById("crore").value = croreAmount;
document.getElementById("lakhs").value = lakhsAmount;
document.getElementById("thousands").innerHTML = thousandsAmount;
document.getElementById("millions").innerHTML = millionsAmount;
document.getElementById("billions").innerHTML = billionsAmount;
document.getElementById("trillions").innerHTML = trillionsAmount;
}
function removeCommas() {
// remove commas from inputted number
croreAmount = croreAmount.split(',').join('');
lakhsAmount = lakhsAmount.split(',').join('');
}
function convertCrore() {
getValues();
removeCommas();
// convert numbers to crore
croreAmount = croreAmount * 1;
lakhsAmount = croreAmount * 100;
thousandsAmount = croreAmount * 100000;
millionsAmount = croreAmount * 10;
billionsAmount = croreAmount * 0.01;
trillionsAmount = croreAmount * 0.00001;
formatResults();
writeResults();
document.getElementById("originalNumber").innerHTML = "crore";
}
function convertLakhs() {
getValues();
removeCommas();
// remove commas from input field
croreAmount = croreAmount.split(',').join('');
lakhsAmount = lakhsAmount.split(',').join('');
// convert numbers to lakhs
croreAmount = lakhsAmount * 0.01;
lakhsAmount = lakhsAmount * 1;
thousandsAmount = lakhsAmount * 100;
millionsAmount = lakhsAmount * 0.1;
billionsAmount = lakhsAmount * 0.0001;
trillionsAmount = lakhsAmount * 1.0E-7;
formatResults();
writeResults();
document.getElementById("originalNumber").innerHTML = "lakhs";
}
</script>
</html>