Convert comma to dot in decimal number
I try with this code does not work.
$rsnew['pendiente']= str_replace(',', '.', $rsnew['pendiente']);
and
$rsnew['pendiente'] = floatval(ereg_replace("[^-0-9\.]"."",$rsnew['pendiente']));
I try with this code does not work.
$rsnew['pendiente']= str_replace(',', '.', $rsnew['pendiente']);
and
$rsnew['pendiente'] = floatval(ereg_replace("[^-0-9\.]"."",$rsnew['pendiente']));
Btw, where you placed your code?
in Row Inserting event, Row Inserted event y Row Updating event....
I have used different options, but without results, might not be the right place.
You cannot convert comma to dot in decimal number if you are already using dot (.) character as the decimal point. Just enter the decimal number as usual using dot character.
No need to convert yourself, make sure you have setup the locale settings properly, see PHP Settings -> General Options -> Set Locale in the help file.
the problem is that when a customer enters a number with comma "12,12" in a field that is validated float
jumps an error message, as it should be.
I would like is to create a function in which the customer
If you enter both a number with comma or dot. correct this before automatically.
so do not give the error message.
It is possible?
You may restrict the comma character by simply using "autonumeric jquery plugin". Just Google for it.
You may add your change event to the field to replace comma with dot (Client Scripts->Table-Specific->Add/Copy Page->Startup Script), like:
$(function() {
$("#x<yourfield>").change(function() { // replace <yourfield> with your actual field name
var val1 = $("#x<yourfield>").val();
val1 = val1.replace(/,/g, '.'); // replace all ',' with '.', assume your field only have one comma
$("#x_<yourfield>").val(val1);
});
});
So, you can use Validate: Float for your validation.
thank you very much.
works great