SAP Knowledge Base Article - Public

1588541 - How to set field rounding to x decimal places at runtime in a VS .NET application?

Symptom

  • Field rounding needs to be set at runtime to specific number of decimals
  • Crystal Reports SDK does not have exposed APIs that allow setting of field decimal places

Resolution

  • Use the Crystal Reports RAS SDK
  • Sample code:

Dim crFld As FieldObject

crFld.FieldFormat.CommonFormat.EnableSystemDefault = False
crFld.FieldFormat.RoundingFormat = CrRoundingTypeEnum.crRoundingTypeRoundToTenBillionth
crFld.FieldFormat.NDecimalPlaces = 4

Dim crFldNew As FieldObject = CType(crFld.Clone(True), FieldObject)
crFldNew.FieldFormat.NumericFormat.RoundingFormat = CrRoundingTypeEnum.crRoundingTypeRoundToTenBillionth
boReportClientDocument.ReportDefController.ReportObjectController.Modify(crFld, crFldNew)

  • Note that the code will not create a field, but will only modify an existing field
  • For alternative C# code see the "References" section

Keywords

KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1