Convert comma to dot in decimal number

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
josecnp1
User
Posts: 73

Convert comma to dot in decimal number

Post 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']));


scs
User
Posts: 694

Post by scs »

Btw, where you placed your code?


josecnp1
User
Posts: 73

Post 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.


mobhar
User
Posts: 11734

Post 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.


Webmaster
User
Posts: 9427

Post 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.


josecnp1
User
Posts: 73

Post 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?


mobhar
User
Posts: 11734

Post by mobhar »

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


danielc
User
Posts: 1601

Post 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.


josecnp1
User
Posts: 73

Post by josecnp1 »

thank you very much.
works great


Post Reply