how to display 4 decimals as a percentage?

johnsogjjohnsogj Member Posts: 103
I am calculating a field in report to show the Margin for various items. The result is a 4 decimal number. however, I need it to be displayed as a percentage. ex. ".1234" should be "12.34%". how can I do this? here is my code to make the first calculation. I couldnt figure out how to use the FORMAT function to do this... any ideas?

Margin10 := (XPriceTable."Unit Price" - Item."Unit Cost")/ XPriceTable."Unit Price"

Comments

  • MP_NAVMP_NAV Member Posts: 42
    from a pure math standpoint you would multiply the results by 100 to form a percentage...
    -MP
  • johnsogjjohnsogj Member Posts: 103
    makes perfect sense. it works. now I have


    Margin10 := ((XPriceTable."Unit Price" - Item."Unit Cost")/ XPriceTable."Unit Price") * 100

    but how do I tack on a percentage sign? I tried to just add + '%' at the end but it doesnt like the fact that I'm mixing decimals and text. I also tried to create a new variable as such:

    Margin10B := Margin10 + '%'

    but again, it doesnt like mixing decimals and text...

    any ideas?
  • MP_NAVMP_NAV Member Posts: 42
    Here is a bit of code from a report that assigns the decimal to a text variable and then adds the % sign to the text string: GPMSTRING is my text variable...


    GP := InvoicedAmt - ReturnedAmt + CostAmt;


    IF (InvoicedAmt - ReturnedAmt) = 0 THEN
    GPM := 0
    ELSE
    GPM := ((GP / (InvoicedAmt - ReturnedAmt)) * 100);
    IF STRLEN(FORMAT(ROUND(GPM,2))) > MAXSTRLEN(GPMString) THEN
    GPMString := FORMAT(GPM,MAXSTRLEN(GPMString))
    ELSE BEGIN
    GPMString := FORMAT(ROUND(GPM));
    j := STRPOS(GPMString,'.');
    IF j = 0 THEN
    GPMString := GPMString + '.00'
    ELSE IF j = STRLEN(GPMString) - 1 THEN
    GPMString := GPMString + '0';
    GPMString := GPMString + '%';
    END;
    -MP
Sign In or Register to comment.