cancel
Showing results for 
Search instead for 
Did you mean: 

XI / PI Format Number issue

Former Member
0 Kudos

Hello,

When I process the value 782.785 through format number 0.00 I'm expecting a value 782.79 but the standard Format number function returns 782.78. Standard function appears to round to a higher digit only if the value is greater than 5 like '.786' to '.79' and not rounds up the value for 5.

What could be done to achieve this functionality? is it possible without a UDF ?

Thanks for your help!

Larry.

Accepted Solutions (0)

Answers (5)

Answers (5)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Larry,

You can try the following UDF


public String formatDec(String s,Container container){
try
		{
			s=new Double(new Double(s).doubleValue()+ new Double("0.001").doubleValue()).toString();
			java.text.DecimalFormat df=new java.text.DecimalFormat();
			df.setMaximumFractionDigits(2);
			df.setMinimumFractionDigits(2);
			df.setGroupingUsed(false);
			s=df.format((new Double(s).doubleValue()));
		}
		catch(Exception e)
		{
			return s;
		}
		return s;
}

here is the input and output I received


input=782.785 output=782.79
input=0.0 output=0.00
input=7.784 output=7.78
input=782.790 output=782.79

regards

Anupam

Former Member
0 Kudos

Hi,

I have tested format number in both PI7.0 and 7.1. When i pass the input 782.785 and use format number (0.00). In both PI versions i got the output 782.79 only. Please chekc once again.

Thanks,

Soumya.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Round up and Round down requirements is not fully feasible to implement using standard function. Use this logic in your UDF...

If you declare input as string and return the value also string for the decimal number then below logic

String str = "782.666";
  double d = Double.valueOf(str);
  DecimalFormat de = new DecimalFormat("###.##");
  return (Double.valueOf(de.format(d))).toString();

Note: if you declared input as double or float and return the value double then the below logic will work.

double d = 782.666;
 DecimalFormat de = new DecimalFormat("###.##");
 return  Double.valueOf(de.format(d));

Hope that helps.

Former Member
0 Kudos

Hi,

I can't trust math functions like round etc.... especially in pi 7.0 Sp15,

Please use math functions carefully .. example.. in pi 7.0 sp 15 round(123456789.3) is not 123456789.

i suggest to you use java udf. before finalizing test perfectly especially with large numbers and -ve numbers...

Best Regards,

Subbu

Former Member
0 Kudos

Hi,

For your requirement you don't use Format Number function.

You have to use Round

Regards

Former Member
0 Kudos

Bhavana,

Round changes the number from 782.785 to 783, how do I change to 782.79 instead?

Thanks,

Larry

former_member181962
Active Contributor
0 Kudos

Multiply by 100. (78278.5 )

use round function. (78279)

Divide by 100. (782.79)