I try to input decimal number which is 44.5, but it return 44.0. How do I get correct decimal values when user input?
What I have tried:
<label>Insert value :</label>
<a class="bold scoreClick">Click to change score</a> <div class="bold scoreInputdiv" style="display:none;">
<input class="bold scoreInput" type="number" step="any" size="2" id="score_final_a" value="'.$data['final_score_sectiona'].'"/> /50
<button type="button" class="btn btn-success btnFinalASave">Save</button></div>
$('.scoreClick').on("click", function (e){
e.preventDefault();
var tt = $(this).next('.scoreInputdiv');
tt.show();
$(this).hide();
tt.children('.scoreInput').focus().select();
});
$('.btnFinalASave').on("click", function (e){
e.preventDefault();
var score = $(this);
var a = parseFloat($(score).prev('.scoreInput').val().trim()) || 0;
var assessment_performance_id = <?php echo $data['id'];?>;
var score_final_b = $('#score_final_b').val();
var score_final_c = $('#score_final_c').val();
if (a > 0){
$(score).prev('.scoreInput').val(a.toString());
}
else{
$(score).prev('.scoreInput').val('');
}
$.ajax({
type: 'GET',
url: './ajax/update_final_score_assessment.php',
data: {
'assessment_performance_id' : assessment_performance_id,
'score_final_a' : a.toString(),
'score_final_b' : score_final_b,
'score_final_c' : score_final_c
},
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function(){
},
success: function(data){},
error: function(message){
},
complete: function(){
if (a > 0){
$(score).parent('.scoreInputdiv').prev('a').html(a.toString());
}
else{
$(score).parent('.scoreInputdiv').prev('a').html('-');
}
$(score).parent('.scoreInputdiv').prev('a').show();
$(score).parent('.scoreInputdiv').hide();
}
});
});
My ajax code
<pre><?php
$data = false;
if(isset($_GET['assessment_performance_id'])) {
include_once '../config/general.php';
include_once '../config/db.php';
include_once '../config/myApp.php';
$assessment_performance_id = (int)$_GET['assessment_performance_id'];
$score_final_a = 0;
if (isset($_GET['score_final_a'])){
$score_final_a = (int)$_GET['score_final_a'];
}
$score_final_b = 0;
if (isset($_GET['score_final_b'])){
$score_final_b = (int)$_GET['score_final_b'];
}
$score_final_c = 0;
if (isset($_GET['score_final_c'])){
$score_final_c = (int)$_GET['score_final_c'];
}
$final_overall_score = $score_final_a + $score_final_b + $score_final_c;
$validProcess = true;
if ($validProcess){
$data = true;
if ($score_final_a){
$mySQL = 'UPDATE assessment_performance SET
final_score_sectiona = "'.number_format((float)$score_final_a,1,'.','').'",
final_overall_score = "'.number_format((float)$final_overall_score,1,'.','').'"
WHERE id = '.$assessment_performance_id;
mysql_query($mySQL);
}
if ($score_final_b){
$mySQL = 'UPDATE assessment_performance SET
final_score_sectionb = "'.number_format((float)$score_final_b,1,'.','').'",
final_overall_score = "'.number_format((float)$final_overall_score,1,'.','').'"
WHERE id = '.$assessment_performance_id;
mysql_query($mySQL);
}
if ($score_final_c){
$mySQL = 'UPDATE assessment_performance SET
final_score_sectionc = "'.number_format((float)$score_final_c,1,'.','').'",
final_overall_score = "'.number_format((float)$final_overall_score,1,'.','').'"
WHERE id = '.$assessment_performance_id;
mysql_query($mySQL);
}
}
}
header("Content-type: text/x-json");
print json_encode($data);
?>