Announcement

Collapse
No announcement yet.

Numeric and decimals

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Numeric and decimals

    hello,
    i have a field {pfs_linea} where i put the result of a datediff performed in the onvalidate event of a form.
    the corresponding db field is set as DECIMAL(5,2) because i only need two digits after the floating point stored in the db.

    the result of that datediff operation is often something like this: 12.66666698455810500000 because i am interested in having the differences between two dates in months instead of days so i put the datediff result in a variable and then divide the variable by 30 in order to get months.

    onvalidate
    -----------------
    if({data_progressione} != 'null') {

    $pfs_giorni= sc_date_dif({data_progressione}, "aaaa-mm-dd",{data_inizio_linea}, "aaaa-mm-dd");
    {pfs_linea} = $pfs_giorni/30;

    }
    -------------------
    if inside SC i set the field as "number" i don't see decimals in the form but everything works, meaning that i don't get errors on the form and in the db the value is stored with a value like this: 12.666 which is what i want.
    But if inside SC i set the field as "decimal" in order to see decimals in the form (which is what i want), when i try to save the form i have an error (on the form) saying this:

    Incorrect decimal value: '12,666666666667' for column 'pfs_linea' at row 1

    i tried to change the db field this way DECIMAL(25,20) in order to accept a high number of decimals but it gives me the same error.

    I know i am doing something wrong, but what?
    What is the correct approach?

    Thnak you

  • #2
    maybe i found the problem. the result of this operation in the onvalidate event

    if({data_progressione} != 'null') {

    $pfs_giorni= sc_date_dif({data_progressione}, "aaaa-mm-dd",{data_inizio_linea}, "aaaa-mm-dd");
    {pfs_linea} = $pfs_giorni/30;

    }

    is a decimal with a comma (,) not a dot (.) meaning that i get something like 12,6 not 12.6 and mysql does not accept decimals using commas in the number..but how to change this behaviour?
    wether or not i change the field settings telling sc to use the dot . instead of the comma , it keeps trying to insert the value with the comma...how can i change this?

    Comment

    Working...
    X