Customer Portal

Bug with decimal datatype?

Comments 3

  • Avatar
    admin
    0
    Comment actions Permalink
    Dear jus,

    use this code in your transformation:

    $in.0.longNumber/str2decimal("100.0");


    Then calculation is then done in Decimal domain and therefore precisely. In sample you send is done in Number (float point) domain and therefore not precisely.

    Sample:
    9695684/100=96956.83999 (because of http://en.wikipedia.org/wiki/Floating_p ... y_problems) and that is rounded to 96956.83 when converted to Decimal. You can see precious result by increasing scale of your decimal field.

    You can cache str2decimal("100.0") result if performance is issue for you.
  • Avatar
    dpavlis
    0
    Comment actions Permalink
    Actually, in CTL just use something like this:


    $in.0.longNumber/100.0D


    Which indicates, that the 100.0 constant should be taken as a decimal number (thus the 'D') instead of float (the default). The reason being is that the float arithmetics is faster, but can loose accuracy.

    For more details see: http://doc.cloveretl.com/documentation/ ... -ctl2.html
  • Avatar
    jus
    0
    Comment actions Permalink
    Cool! Thanks guys!

Please sign in to leave a comment.