Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Display 4 decimals only and remove trailing zeros

Hello,

I have CR XI used in .net windows application.

I need a formula that will display a decimal value with minimum 2 decimals and 4 decimals characters (if needed) and will remove all trailing zeros.

Examples:

100 -> 100.00

100.1234 -> 100.1234

100.1200 -> 100.12

Thanks

Edited by: mtlmonk on Apr 27, 2009 7:22 PM

Former Member
replied

Try creating a formula in the report like this

This formula works upto 10 decimal places.

local NumberVar n := {Decimal Field}
NumberVar Zeros;
StringVar DecimalPortion;

DecimalPortion := ToText (n - (Truncate (n)), 10);

if DecimalPortion[12] <> "0" then Zeros := 10 
else if DecimalPortion[11] <> "0" then Zeros := 9 
else if DecimalPortion[10] <> "0" then Zeros := 8
else if DecimalPortion[9] <> "0" then Zeros := 7
else if DecimalPortion[8] <> "0" then Zeros := 6
else if DecimalPortion[7] <> "0" then Zeros := 5
else if DecimalPortion[6] <> "0" then Zeros := 4
else if DecimalPortion[5] <> "0" then Zeros := 3
else if DecimalPortion[4] <> "0" then Zeros := 2
else if DecimalPortion[3] <> "0" then Zeros := 1
else Zeros := 0;


if Zeros>2 then
totext(n,Zeros)
else
totext(n,2)

Hope this helps!

Raghavendra

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question