Topic
  • 4 replies
  • Latest Post - ‏2013-11-20T09:18:57Z by Bhoju
Rshya
Rshya
24 Posts

Pinned topic Decimal digits in WTX

‏2013-10-15T03:13:15Z |

Hi All,

 

I have an input field when its value is 4.99900 then i need to see 4.999 in the output. While if the input has 4.99000 the i need to see 4.99, while if the input has 4.90000 then i need to see 4.90, and if input has 4.00000 then i need to see 4.00

I have considered both input and output fields as Text and they are 8 char fixed length. Can any body please tell me how to solve this in WTX??

 

Thanks,

Rshya

  • thorstenhirsch
    thorstenhirsch
    87 Posts

    Re: Decimal digits in WTX

    ‏2013-10-15T10:06:06Z  

    Yes, I think going with a text field is a good decision here. I would also distinct between the whole number and the fraction, so let's give it a try:

    = WORD(input, '.', 1) // take whole number as it is

    + '.'

    // fraction is more complicate

    + FILLRIGHT(TRIMRIGHT(WORD(input, '.', 2), "0"), "0", 2)

    So we only remove '0' on the right side of the fraction (4.999 would still be 4.999) and then we fill the fraction up to 2 digits with '0' (4.9 becomes 4.90).

    P.S.: The WYSIWYG editor here is crappy.

    Updated on 2013-10-15T10:08:38Z at 2013-10-15T10:08:38Z by thorstenhirsch
  • Rshya
    Rshya
    24 Posts

    Re: Decimal digits in WTX

    ‏2013-10-15T14:04:56Z  

    Yes, I think going with a text field is a good decision here. I would also distinct between the whole number and the fraction, so let's give it a try:

    = WORD(input, '.', 1) // take whole number as it is

    + '.'

    // fraction is more complicate

    + FILLRIGHT(TRIMRIGHT(WORD(input, '.', 2), "0"), "0", 2)

    So we only remove '0' on the right side of the fraction (4.999 would still be 4.999) and then we fill the fraction up to 2 digits with '0' (4.9 becomes 4.90).

    P.S.: The WYSIWYG editor here is crappy.

    Thanks so much thorstenhirsch, it worked. but it is just that I had to put decimal point within double quotes and not single quotes and it worked. Thanks again!!

     

    Thanks,

    Rshya

  • Rshya
    Rshya
    24 Posts

    Re: Decimal digits in WTX

    ‏2013-10-16T19:18:37Z  

    Yes, I think going with a text field is a good decision here. I would also distinct between the whole number and the fraction, so let's give it a try:

    = WORD(input, '.', 1) // take whole number as it is

    + '.'

    // fraction is more complicate

    + FILLRIGHT(TRIMRIGHT(WORD(input, '.', 2), "0"), "0", 2)

    So we only remove '0' on the right side of the fraction (4.999 would still be 4.999) and then we fill the fraction up to 2 digits with '0' (4.9 becomes 4.90).

    P.S.: The WYSIWYG editor here is crappy.

    Hi thorstenhirsch, I have a doubt here, when the input had 4.90000 it became 4.90, but when the the input had 4.00000, then it is showing only 4. and not 4.00.

    Couls you please tell me how to get 4.00 in this case??

     

    Thanks,

    Rshya

  • Bhoju
    Bhoju
    37 Posts

    Re: Decimal digits in WTX

    ‏2013-11-20T09:18:57Z  
    • Rshya
    • ‏2013-10-16T19:18:37Z

    Hi thorstenhirsch, I have a doubt here, when the input had 4.90000 it became 4.90, but when the the input had 4.00000, then it is showing only 4. and not 4.00.

    Couls you please tell me how to get 4.00 in this case??

     

    Thanks,

    Rshya

    Try this.. i think it should work..

     

    if ( right(<youritem>, 2) = "00" & right(<youritem>, 2) != "000", // then
    numbertotext(truncate (texttonumber(<youritem>), 3))
    //else
    ,numbertotext(truncate (texttonumber(<youritem>), 2))
    )