1
The system does not work when typing number with comma, for example 2,14, 22,14 and so on... only with end point 2.14, 22.14 and so on... Below the function I use. How to use function with the number typed with comma, do not display ERROR Nan and the result also appear with comma. Would it be possible to restrict the use of dot in the field or even issue an alert if the user type "."? Thank you very much.
<script>
$(function(){
$('.temp').change(function(){
var total = 0;
var notas = 0;
$('.temp').each(function(){
var nota = Number(this.value);
if(nota === 0) return;
total = total + nota;
notas++;
})
var t = (total/notas).toFixed(2);
$('#media_temperaturaE').val(t);
});
})
Below the number typing screen to perform the calculation, with the two examples.
Friend, take a look at this post: http://answall.com/questions/54691/mudar-ponto-por-virgula-em-value-de-input The solution is to replace the code, to change the comma to a point.
– user50975
This . replace('.', ','); resolves the final result of the operation, but I still have to put "." for the calculation of my average function to work. I want a solution in which my function works with comma numbers, for example 2.1 and the result does not occur NAN ERROR.
– Quito Gaspar
The point is, I don’t know if Javascript accepts comma calculus. Programming languages usually divide the entire fraction using dots.
– user50975
The Nan error happens because the value contained in the variable is a string "Not a Number".
– user50975
http://www.w3schools.com/js/js_numbers.asp
– Pedro Camara Junior