Page 1 of 1

Convert comma to dot in decimal number

Posted: Sun Dec 07, 2014 6:33 am
by josecnp1

I try with this code does not work.

$rsnew['pendiente']= str_replace(',', '.', $rsnew['pendiente']);

and

$rsnew['pendiente'] = floatval(ereg_replace("[^-0-9\.]"."",$rsnew['pendiente']));


Re: Convert comma to dot in decimal number

Posted: Sun Dec 07, 2014 10:06 am
by scs

Btw, where you placed your code?


Re: Convert comma to dot in decimal number

Posted: Sun Dec 07, 2014 7:04 pm
by josecnp1

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.


Re: Convert comma to dot in decimal number

Posted: Mon Dec 08, 2014 9:43 am
by mobhar

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.


Re: Convert comma to dot in decimal number

Posted: Mon Dec 08, 2014 9:54 am
by Webmaster

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.


Re: Convert comma to dot in decimal number

Posted: Mon Dec 08, 2014 11:34 pm
by josecnp1

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?


Re: Convert comma to dot in decimal number

Posted: Tue Dec 09, 2014 9:10 am
by mobhar

You may restrict the comma character by simply using "autonumeric jquery plugin". Just Google for it.


Re: Convert comma to dot in decimal number

Posted: Tue Dec 09, 2014 12:56 pm
by danielc

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.


Re: Convert comma to dot in decimal number

Posted: Tue Dec 09, 2014 3:17 pm
by josecnp1

thank you very much.
works great