cancel
Showing results for 
Search instead for 
Did you mean: 

Format a decimal number coming from a BAPI

Former Member
0 Kudos

Hi,

I have a requirement where I need to format a decimal number in a table and display it in the following format:

1. If its a whole number, I need to display it as <Whole number>.00

( Suffix of '00' is a must )

Eg: 2 must be displayed as 2.00

2. If its not a whole number I need to display only 6 decimals after the decimal point.

Eg. 0.231876208 must be displayed as 0.231876

The data in the table is coming from a BAPI and is of the type double.

Can anyone let me know how I can achieve this?

Thanks in advance,

Reena

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Reena,

Check out these threads:

Warm Regards,

Bala

Former Member
0 Kudos

Hi Bala,

Thanks a ton.

The third link helped me a lot.

Regards,

Reena

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Reena,

This is how you can implement your logic

1. To check whether it is a whole number or an integer:

   double BAPIValue; // stores the Value from BAPI
   String test = BAPIValue.toString();

// Now you have to check the string whether there it is haveing a '.'. If it has a '.' then it is a decimal number else it is not.

    if (decimal number) {
        DecimalFormat formatdecimal = new DecimalFormat ("#0.000000");
        String Formattedvalue = formatdecimal.format(BAPIValue);
    } else { // it is a whole number
              DecimalFormat formatdecimal = new DecimalFormat ("#0.00");
        String Formattedvalue = formatdecimal.format(BAPIValue);
    }

Hope this will solve your problem. If you further have problems please do let me know.

Thanks & Regards

--Vishal Sood

<b>PS: Please provide points for helpful answers</b>