tags:

views:

46

answers:

1

NOTE: This is from a Joomla component.

The Problem: When I enter, say, 4.90 into the price input box and hit save the price becomes 5, etc. I need for the value to remain as entered.


I've tracked down this block of code in the form.php looks like it might be the right one, but I can't figure out what needs to change:

function toTransFloat( input )
    {
        value = input.value;
        if ( value != null && value.length != 0 )
            value = value.replace( ',' , '.' );
        else 
            return false;

        input.value = ( isNaN( parseFloat( value ) ) == false ? parseFloat( value ) : "" ); 
        return input.value;
    }

help ... ?

A: 

I doubt that changing the Joomla code is really what you need to do; I'm not familiar with Joomla, but in Drupal if you're creating a form you can define the type of data you expect. Check that the field you're checking has not been defined as an integer type of field - that may help.

If not, I'm not sure, but messing with the code from the CMS or framework that you're using is going to cause you pain when you need to upgrade in the future - and for something like this, it's almost certainly unnecessary.

El Yobo
Actually, it's ok I am not modifying the CMS code, just the code of a 3rd party component (which I have a backup copy of).Thanks for the suggestion. I'm pretty sure the field is names 'prix'... so with that in mind...could this be it?`prix` int(11) DEFAULT NULL,or this?var $prix = 0;
Aidan
The first example you give there looks like a field definition for the database; if that's where your data is being stored, the database itself is probably converting your float into an int when it gets stored. If you're using MySQL, you can change the schema (assuming a table name of "mytable") with "ALTER TABLE mytable CHANGE COLUMN prix prix FLOAT;"
El Yobo
Thanks El Yobo, would I run that string from php myadmin? RE:"prix int(11)", does the int(11) mean that the value for prix will be an integer?
Aidan
Yes. prix is the database field name and int(11) is the type. Integer fields will generally either round or truncate a float to get an integer value. The CHANGE COLUMN statement will change the field type to a floating point type, which will store 4.9 as 4.9 rather than rounding it to 5.
El Yobo
I changed the 'prix' column of the DB table to float as you suggested and now it is storing values like 4.90. Fantastic! I've also modified the 'prix int(11) DEFAULT NULL' code to 'prix float DEFAULT NULL' for future use of the component.Your guidance is greatly appreciated El Yobo.
Aidan