Decimal values lost

Permalink
Who has this problem, how to fix it?

After inserting a decimal value (ie 3.14145) into a text field (any text field, in add or edit mode) the decimal gets lopped off and the displayed value is before the decimal point.

Anyone fixed this? Is this in the save() function in concrete/controller.php ?

WJ

webjedi
 
Mnkras replied on at Permalink Reply
Mnkras
i think it might be the code cleaner,
ScottC replied on at Permalink Reply
ScottC
well most stuff is an integer and gets converted as such.

if you have a block or another concrete5 added db table and thus field it is recommended by me to use either a N or F designation in your db.xml, otherwise mysql won't convert it to an integer which is a whole number.

I settled on type of N for my app dealing with numbers and money, not sure why at the time but that is what i did :) Float might be more applicable for storing pi
webjedi replied on at Permalink Reply
webjedi
Dang, that can't be it.

I have had it set to N since it's creation:

<field name="price" type="N">
</field>

It is somewhere when I submit the form, I think it's code cleaner too (but I can't find code cleaner yet) here is the form field:

<h2><?=t('Price')?></h2>
<?= $form->text('price', $price, array('style' => 'width: 280px')); ?>


*** UPDATE ***

I have temporarily solved it by making the DB field type X and it stores it as a string.
mose replied on at Permalink Reply
mose
Don't you have to specify a size like 6.2 (six digits followed by two decimal places) when using N? The documentation for ADOXMLS recommends using a string type for decimals to avoid rounding errors. If only two decimal places are ever used, that shouldn't be a problem. An issue would only occur if two decimal places are specified for the field but a value with more than two decimal places is being stored in the field.
rockface replied on at Permalink Reply
rockface
Has anyone found a way to store decimal values yet?
When using type="N" it creates a field type of "decimal(10,0)" which rounds off the decimal. Attempting to use something like type="N10.2" generates an mysql error: 1064 during the block install. I simply can't believe we have to settle on storing them as string values.

PLEASE HELP!
rockface replied on at Permalink Reply
rockface
Found a solution!

<table name="bt_Timecard"> 
    <field name="tcID" type="I">
      <key />
      <autoincrement />         
      <unsigned />
    </field>
    <field name="taskID"    type="I" />
    <field name="Date"      type="T" />
    <field name="Hours"     type="decimal(6, 2)" />
  </table>
clomads replied on at Permalink Reply
Thanks for this. Works like a charm.
rockface replied on at Permalink Reply
rockface
If you're using Concrete5 5.7, I found this will create a field defined as "decimal(10,2)"

In the db.xml use this format:
<field name="Price" type="N" size="10.2"></field>

You can find even more gold nuggets in: \concrete\src\Database\Schema\Parser\Axmls.php