crystal-reportsformula

Formula to change how a number is displayed in crystal reports


I’m creating a pallet label for a customer in crystal reports, and need to change the weight field data so I can add it into a barcode Example, 663.12 to display as 066312

The end figure will need be 6 digits in lenght, but the start figure could be 7 digits in lenght with deicmal point

Is there a formula to achieve this the final figure is then added into the barcode Thanks Lee

I can sort of achive this by using the left right functions, but its only a work around "0" & left(({@net weight}),3) & right(({@net weight}),2) this is ok until the weight goes above 1000 then i get a return of 010000


Solution

  • Try this formula.

    CStr(663.12 * 100, "000000")
    

    This converts the data to a string. The format string ensures there are always 6 characters in the string output, and will default to a leading zero when the value being converted has less than 6 characters. Multiplying the value by 100 removes the decimal.

    Using this formula, your value of 663.12 would become 066312. While a value of 63.12 would become 006312. and a value of 0.01 would become 000001.