cancel
Showing results for 
Search instead for 
Did you mean: 

Increase the precision for a number (floating point) column via the Crystal Reports Java SDK

Former Member
0 Kudos

(Here's the question that I posted on http://stackoverflow.com/questions/23897994/increase-the-precision-for-a-number-floating-point-colum... - posting here for hopefully some comments - reposted from a previous SAP discussion)

I'm a newbie when it comes to making use of the crystal reports java sdk (Business Objects 4.1), and I'm running into a frustrating issue. I'm attempting to augment the format of a dynamically generated column in Excel/CSV that happens to be representing a floating point number (percentage), but when no matter what I've done with INumericFieldFormat, I can't get the output I need.

Take for instance 0.0625 - when it is rendered in Excel, the cell displays it as 0.06 (two decimal places), but the actual value when you click on the cell shows up correctly in the formula bar. For CSV, the output is always truncated at 2 decimal places. What I was hoping for was to set the number of decimal places and rounding format, and that would properly display the number.

Here's a snippet of my code so far:

    INumericFieldFormat numericFieldFormat = new NumericFieldFormat();

    numericFieldFormat.setNDecimalPlaces(10); // User wants to see up to 10 decimal places

    numericFieldFormat.setDecimalSymbol(".");

    numericFieldFormat.setThousandsSeparator(false);

    // supports the 10 decimal requirement

    numericFieldFormat.setRoundingFormat(RoundingType.roundToTenBillionth);

    numericFieldFormat.setEnableUseLeadZero(true);

    numericFieldFormat.setConditionFormulas(null);

    final ICommonFieldFormat commonFieldFormat = new CommonFieldFormat();

    commonFieldFormat.setEnableSystemDefault(false);

    final IFieldFormat fieldFormat = fieldObject.getFieldFormat();

    fieldFormat.setNumericFormat(numericFieldFormat);

    fieldFormat.setCommonFormat(commonFieldFormat);

    fieldObject.setFieldFormat(fieldFormat);

So far I've been able to make the Excel output look like 0.0600000000 and the CSV output look like 600000000, but that's not what I need. Any help is appreciated!

Update

One thing I've noticed, is that adding a formula to do the formatting, for the most part, gives a "bad formula result" error:

    ConditionFormula roundingFormula = new ConditionFormula();

    roundingFormula.setFormulaNullTreatment(FormulaNullTreatment.asDefaultValue);

    roundingFormula.setSyntax(FormulaSyntax.crystal);

    roundingFormula.setText("Round(" + crystalDatasetField.getFormulaForm() + ",10)");

    ...

    roundingFormula.setText("Numbervar x; x := " + crystalDatasetField.getFormulaForm() + "; x := Round(x, 10)");

    ...

    roundingFormula.setText("ToNumber(ToText(" + crystalDatasetField.getFormulaForm() + ",\"0.00\",10))");

However, the following works, but rounds to the zeroth place:

    ConditionFormula roundingFormula = new ConditionFormula();

    roundingFormula.setFormulaNullTreatment(FormulaNullTreatment.asDefaultValue);

    roundingFormula.setSyntax(FormulaSyntax.crystal);

    roundingFormula.setText("Round(" + crystalDatasetField.getFormulaForm() + ")");

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Here's a more fleshed out version that makes use of the NumericFieldFormat - I still haven't been able to get this to round or display to the 10th decimal;

  

INumericFieldFormat numericFieldFormat =  new NumericFieldFormat();

   numericFieldFormat.setAllowFieldClipping(false);
   numericFieldFormat.setCurrencySymbolFormat(CurrencySymbolType.noSymbol);
   numericFieldFormat.setCurrencySymbol("");
   numericFieldFormat.setCurrencyPosition(CurrencyPositionFormat.leadingCurrencyOutsideNegative);
   numericFieldFormat.setDecimalSymbol(".");
   numericFieldFormat.setDisplayReverseSign(false);
   numericFieldFormat.setEnableSuppressIfZero(false);
   numericFieldFormat.setEnableUseLeadZero(true);
   numericFieldFormat.setNDecimalPlaces(10);
   numericFieldFormat.setNegativeFormat(NegativeType.leadingMinus);
   numericFieldFormat.setOneCurrencySymbolPerPage(false);
   numericFieldFormat.setRoundingFormat(RoundingType.roundToTenBillionth);
   numericFieldFormat.setThousandsSeparator(false);
   numericFieldFormat.setThousandSymbol(",");
   numericFieldFormat.setUseAccountingFormat(false);
   numericFieldFormat.setZeroValueString("0");
  

numericFieldFormat.setConditionFormulas(null);

  

final ICommonFieldFormat commonFieldFormat = new CommonFieldFormat();

   commonFieldFormat.setEnableSuppressIfDuplicated(false);
   commonFieldFormat.setEnableSystemDefault(false);
  

commonFieldFormat.setConditionFormulas(null);

  

final IObjectFormat objectFormat = new ObjectFormat();

   objectFormat.setAllowCustomizeInTemplate(true);
   objectFormat.setEnableSuppress(false);
   objectFormat.setEnableKeepTogether(true);
   objectFormat.setEnableCloseAtPageBreak(true);
   objectFormat.setHorizontalAlignment(Alignment.useDefault);
   objectFormat.setEnableCanGrow(true);
   objectFormat.setToolTipText(StringUtils.EMPTY);
   objectFormat.setCssClass(StringUtils.EMPTY);
   objectFormat.setConditionFormulas(null);
   objectFormat.setHyperlinkText(StringUtils.EMPTY);
   objectFormat.setHyperlinkType(HyperlinkType.undefined);
  

objectFormat.setTextRotationAngle(TextRotationAngle.rotate0);

  

final IFieldFormat fieldFormat = new FieldFormat();

   fieldFormat.setNumericFormat(numericFieldFormat);
   fieldFormat.setCommonFormat(commonFieldFormat);
   fieldObject.setFieldFormat(fieldFormat);
   fieldObject.setFormat(objectFormat);
  
   reportDefController.getReportObjectController().add(fieldObject, section, -1);