aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html32
1 files changed, 21 insertions, 11 deletions
diff --git a/index.html b/index.html
index 39697ff..65ee3f8 100644
--- a/index.html
+++ b/index.html
@@ -97,14 +97,14 @@ main {
</header>
<main>
<div class="section">
- <input class="form-ctl" type="number" id="a" placeholder="A">
+ <input class="form-ctl" pattern="([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]" type="text" id="a" placeholder="A">
&nbsp;=&nbsp;
- <input class="form-ctl" type="number" id="b" placeholder="B">
+ <input class="form-ctl" pattern="([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]"type="text" id="b" placeholder="B">
</div>
<div class="section">
- <input class="form-ctl" type="number" id="c" placeholder="C">
+ <input class="form-ctl" pattern="([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]" type="text" id="c" placeholder="C">
&nbsp;=&nbsp;
- <input class="form-ctl" type="number" id="resultado" disabled placeholder="Resultado">
+ <input class="form-ctl" pattern="([0-9]+.{0,1}[0-9]*,{0,1})*[0-9]" id="resultado" disabled placeholder="Resultado">
</div>
<div id="warning" class="section warning">
<p>
@@ -122,14 +122,24 @@ const cInput = document.getElementById('c')
const resultadoInput = document.getElementById('resultado')
const warningParagraph = document.getElementById('warning')
+function cToP(v) {
+ return v.replace(",", ".")
+}
+
+function pToC(v) {
+ return v.replace(".", ",")
+}
+
function eval() {
- const a = aInput.value
- const b = bInput.value
- const c = cInput.value
+ const a = cToP(aInput.value)
+ const b = cToP(bInput.value)
+ const c = cToP(cInput.value)
try {
const values = validate(a,b,c)
- resultadoInput.value = calculate(...values)
+ // fix float to 3 and remove zeroes
+ const result = calculate(...values).toFixed(3).replace(/\.0+$/,'')
+ resultadoInput.value = pToC(result)
} catch (e) {
warningParagraph.textContent = e
warningParagraph.style.visibility = 'visible';
@@ -142,19 +152,19 @@ function eval() {
function validate(a, b, c) {
const result = [0,0,0]
- const ra = parseInt(a)
+ const ra = parseFloat(a)
if (isNaN(ra)){
throw "Valor de A invalido"
}
result[0] = ra
- const rb = parseInt(b)
+ const rb = parseFloat(b)
if (isNaN(rb)){
throw "Valor de B invalido"
}
result[1] = rb
- const rc = parseInt(c)
+ const rc = parseFloat(c)
if (isNaN(rc)){
throw "Valor de C invalido"
}