How to remove Decimal point in decimal field?

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Pals,

My requirement is I need to pad a decimal field with zeros to which the total length is 15. After the decimal point it should contain 3 digits.

Field/Variable details:
VATNetAmount = Total of "VAT Base Amount" in Sales Invoice Line table.
strVATNetAmount = Code 20

For eg: If the decimal field (VATNetAmount) is 54321.78 means, I must get the output as 000000054321780. At the end of the decimal part it should display with 0 (zero) when it contains only 2 digits. Also I need to remove the decimal point.

Almost I achieved it by doing the following piece of code.
VATNetAmount := VATNetAmount + SIL_VAT."VAT Base Amount";
strVATNetAmount2 := PADSTR('',15 - STRLEN(FORMAT(ROUND(VATNetAmount,0.001), 0, '<Precision,3:3><Standard Format,2>')),'x') + FORMAT(VATNetAmount, 0,'<Precision,3:3><Standard Format,2>');

But I am getting the out put as XXXXXX54321.780. Here I need to remove the decimal point and and preceeded with zero at starting of the decimal field.

Can anyone help me out in achieving this?

Thanks,
Aravindh.

Answers

  • BeliasBelias Member Posts: 2,998
    dec := 500.23;
    integerpart := format(dec,0,'<Integer,12><Filler Character,0>');
    decimalpart := format(dec,0,'<Decimals,4><Filler Character,0>');
    decimalpart := delchr(decimalpart,'=',',');
    message(integerpart + decimalpart);
    
    It's raw and hardcoded, but you can elaborate it a bit (take a look at format property in the online help)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • josep_jordijosep_jordi Member Posts: 9
    Hi Pals,

    My requirement is I need to pad a decimal field with zeros to which the total length is 15. After the decimal point it should contain 3 digits.

    Field/Variable details:
    VATNetAmount = Total of "VAT Base Amount" in Sales Invoice Line table.
    strVATNetAmount = Code 20
    

    For eg: If the decimal field (VATNetAmount) is 54321.78 means, I must get the output as 000000054321780. At the end of the decimal part it should display with 0 (zero) when it contains only 2 digits. Also I need to remove the decimal point.

    Almost I achieved it by doing the following piece of code.
    VATNetAmount := VATNetAmount + SIL_VAT."VAT Base Amount";
    strVATNetAmount2 := PADSTR('',15 - STRLEN(FORMAT(ROUND(VATNetAmount,0.001), 0, '<Precision,3:3><Standard Format,2>')),'x') + FORMAT(VATNetAmount, 0,'<Precision,3:3><Standard Format,2>');
    

    But I am getting the out put as XXXXXX54321.780. Here I need to remove the decimal point and and preceeded with zero at starting of the decimal field.

    Can anyone help me out in achieving this?

    Thanks,
    Aravindh.

    You can try with :
    VATNetAmount            := 54321.78;
    VATNetAmountNoDec    := ROUND(VATNetAmount,1,'<');
    VATNetAmountDecimals := (VATNetAmount-VATNetAmountNoDec)*1000;
    
    strVATNetAmount2     := FORMAT(VATNetAmountNoDec, 0, '<Precision,0:0><Standard Format,2>')+
                            FORMAT(VATNetAmountDecimals, 0, '<Precision,0:0><Standard Format,2>');
    
    strVATNetAmount2     := '000000000000000'+DELCHR(strVATNetAmount2);
    strVATNetAmount2     := COPYSTR(strVATNetAmount2,STRLEN(strVATNetAmount2)-14,15);
    
    
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Hi Joseph_Jordi/Belias,

    Thanks a lot for your response. Both the approach are working. :D \:D/

    Aravindh.
  • kinekine Member Posts: 12,562
    What is wrong with this code?
    VATNetAmount := ROUND(VATNetAmount,0.001) *1000;
    strVATNetAmount := FORMAT(VATNetAmount,0,'<Integer,12><Filler Character,0>');
    

    Why so long code for such a easy task? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    kine wrote:
    What is wrong with this code?
    VATNetAmount := ROUND(VATNetAmount,0.001) *1000;
    strVATNetAmount := FORMAT(VATNetAmount,0,'<Integer,12><Filler Character,0>');
    

    Why so long code for such a easy task? ;-)
    :thumbsup:
    But i was wondering...it's very strange that the the <Decimals> part of the format function does not have a way to remove the comma...just like we do with <Integer>/<Integer thousand> ...well, it's easy solvable with your code, but it's curious that we can't obtain just the decimal part with one function only :-k
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.