Inline editing 4.2 appearing as 4.1999998

Inline editing 4.2 appearing as 4.1999998

ShaneBrennanShaneBrennan Posts: 47Questions: 17Answers: 1

Using datatable and Editor (in line) to allow a user to enter sample results.

Numbers such as 4.2 are being stores correctly in MY MSSQL DB but being displayed with a floating point error (I assume). Anywas I've got found the initial display by using ColumnDefs on the Datatable:

        columnDefs: [
          {
              render: $.fn.dataTable.render.number(',', '.', 1),
              targets: [3,4,5,6,7,8]
           }
        ],

which is great, however when I click in the 4.2 Aspergillus in the 2nd row I get:

Is there something similar to the columnDef for the datatable I can use? or is there another solution to get it to be 4.2 instead?

Thank you inadvance for any help given

Answers

  • colincolin Posts: 7,698Questions: 0Answers: 1,298

    Can you post the JSON that's returned from the server for that record, please. I'd be interested to see if that has 4.2 or the incorrect number.

    Colin

  • ShaneBrennanShaneBrennan Posts: 47Questions: 17Answers: 1

    Hi Colin... your right...The JSON is presenting the wrong value:

    MSSQL is showing the correct values:

    just need the editor to round it up to 1 dp

  • allanallan Posts: 51,272Questions: 1Answers: 7,725 Site admin

    On the client-side Editor doesn't have a formatter for modifying values as they go into a field for editing. It always operates on the raw value.

    So the solution here would be to understand why you are getting 4.19999... in the JSON data in the first place. I would have assumed it was being stored as an IEEE754 number with its limited precision (which is what Javascript uses), but it is shown as a string above, so I'm not certain that is the issue.

    Perhaps you can clarify where the data is coming from and if it is 4.19999... in the data store, whatever that is.

    Allan

  • ShaneBrennanShaneBrennan Posts: 47Questions: 17Answers: 1
    edited February 14

    basically I use PHP, this is what I use to retrieve the data from MSSQL and convert to JSON.

    use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

    $reqID = 0;
    if (isset($_GET['projectID'])) {
    $reqID = $_GET['projectID'];
    // ToCleaned($reqID);
    }

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'tblAQIlocationSamples' )
    ->field(
    Field::inst( 'tblAQIlocationSamples.id' ),
    Field::inst( 'tblAQIlocsAndMeasures.locationNo' ),
    Field::inst( 'tblAQIlocsAndMeasures.locationName' ),
    Field::inst( 'tblAQIlocationSamples.sampleNo' ),
    Field::inst( 'tblAQIlocationSamples.bacteriaCFU' ),
    Field::inst( 'tblAQIlocationSamples.aspergillusCFU' ),
    Field::inst( 'tblAQIlocationSamples.totalMouldCFU' ),
    Field::inst( 'tblAQIlocationSamples.yeastCFU' ),
    Field::inst( 'tblAQIlocationSamples.penicilliumCFU' )
    )
    ->where('tblAQIlocationSamples.projectID',$reqID)
    ->where('tblAQIlocationSamples.sampleType','Airstrip')
    ->leftjoin( 'tblAQIlocsAndMeasures', 'tblAQIlocsAndMeasures.id', '=', 'tblAQIlocationSamples.AQIlocationID' )
    ->process( $_POST )
    ->json();

    and this is the JSON response:

    {"data":[{"DT_RowId":"row_14","tblAQIlocationSamples":{"id":"14","sampleNo":"1","bacteriaCFU":"5.0","aspergillusCFU":"4.0","totalMouldCFU":"26.0","yeastCFU":"5.0","penicilliumCFU":"3.0"},"tblAQIlocsAndMeasures":{"locationNo":"01","locationName":"Outside"}},{"DT_RowId":"row_17","tblAQIlocationSamples":{"id":"17","sampleNo":"4","bacteriaCFU":"1.0","aspergillusCFU":"6.0","totalMouldCFU":"2.0","yeastCFU":"5.0","penicilliumCFU":"3.0"},"tblAQIlocsAndMeasures":{"locationNo":"02","locationName":"Dining Room no 2"}}],"options":[],"files":[]}

  • allanallan Posts: 51,272Questions: 1Answers: 7,725 Site admin

    Thanks. In the JSON response there is "aspergillusCFU":"4.0" and "aspergillusCFU":"6.0" which I presume are okay?

    But from your comment before when it is 4.2 there is an issue - and the JSON return is actually 4.19999...? Which is odd since those numbers are actually strings - there shouldn't be any rounding.

    Thanks,
    Allan

Sign In or Register to comment.