can't figure out how to turn off rounding

(2 posts) (2 voices)

Tags:

No tags yet.

  1. john, Member

    followed along with the example "Source code for report "Edit cell and set value for another cell"
    https://mydbr.com/demo/mydbr/report.php?r=3&p1=sp_DBR_editable_two%2Csp_DBR_editable_two_edit&m=4&h=1c844ba15061ab9b55202e7a12395d7a4ec4f8fb&i=1

    Trying to make the value of the second column display with decimals, it will only display whole numbers.

    The type of my second column is a decimal(13,2). The value set by the Javascript code always seems to round to whole numbers. Instead of displaying 641.50 it displays 642 and instead of 64.15 it displays 64
    if i refresh the page it loads with 2 decimals.
    I have tried a column style for more than one decimal but that doesn't work either.
    the javascript alert shows 2 decimals


    select 'dbr.editable', '[q]', 'sp_DBR_update_tbl_project1_decimal', 'inid=id','type=autosize', "options={'callback':twoparams}"; select 'dbr.javascript', 'function twoparams(value, settings)
    {
    /*
    When returning more than one parameter, value is a JSON string that you can convert to JavaScript object with jQuery.parseJSON
    */
    var o = jQuery.parseJSON(value); alert ( parseFloat(o.total).toFixed(2)) col_value_text( this, this.cellIndex+1, o.qty );
    col_value_set( this, this.cellIndex+2, 0, parseFloat(o.total).toFixed(2) );
    }'; select
    p.id,
    p.Qty as 'Qty[q]',
    p.Total as 'Total',
    from test.table121 p;

  2. myDBR Team, Key Master

    John,
    the third parameter of the col_value_set() is the number of decimals to show. Just change the line to read:

    col_value_set( this, this.cellIndex+2, 2, o.total );

    --
    myDBR Team


Reply

You must log in to post.