diff --git a/src/modules/__tests__/renderValue.spec.js b/src/modules/__tests__/renderValue.spec.js index 845629bbe..eaf3d2a7c 100644 --- a/src/modules/__tests__/renderValue.spec.js +++ b/src/modules/__tests__/renderValue.spec.js @@ -25,21 +25,21 @@ const tests = [ // Numbers { value: 1000.5, - expected: '1 000.5', + expected: '1 000.50', valueType: VALUE_TYPE_NUMBER, round: true, dgs: DGS_SPACE, }, { - value: 33777889.55, - expected: '33,777,889.5', + value: 33777889.555, + expected: '33,777,889.55', valueType: VALUE_TYPE_NUMBER, round: true, dgs: DGS_COMMA, }, { value: 33777889.556, - expected: '33 777 889.6', + expected: '33 777 889.56', valueType: VALUE_TYPE_NUMBER, round: true, dgs: DGS_SPACE, @@ -53,7 +53,7 @@ const tests = [ }, { value: 33777889.56, - expected: '33777889.6', + expected: '33777889.56', valueType: VALUE_TYPE_NUMBER, round: true, dgs: DGS_NONE, @@ -74,7 +74,7 @@ const tests = [ }, { value: 1.101, - expected: '1.1', + expected: '1.10', valueType: VALUE_TYPE_NUMBER, round: true, dgs: DGS_SPACE, @@ -135,16 +135,16 @@ const tests = [ dgs: DGS_SPACE, }, { - value: -0.0234, - expected: '-2.3%', + value: -0.02345, + expected: '-2.34%', valueType: VALUE_TYPE_NUMBER, numberType: NUMBER_TYPE_ROW_PERCENTAGE, round: true, dgs: DGS_SPACE, }, { - value: -0.0234, - expected: '-2.34%', + value: -0.02345, + expected: '-2.345%', valueType: VALUE_TYPE_NUMBER, numberType: NUMBER_TYPE_ROW_PERCENTAGE, round: false, diff --git a/src/modules/pivotTable/PivotTableEngine.js b/src/modules/pivotTable/PivotTableEngine.js index 7b90e0935..6d16a8985 100644 --- a/src/modules/pivotTable/PivotTableEngine.js +++ b/src/modules/pivotTable/PivotTableEngine.js @@ -8,7 +8,12 @@ import { } from '../dataTypes.js' import { DIMENSION_ID_ORGUNIT } from '../predefinedDimensions.js' import { renderValue } from '../renderValue.js' -import { VALUE_TYPE_NUMBER, VALUE_TYPE_TEXT } from '../valueTypes.js' +import { + VALUE_TYPE_NUMBER, + VALUE_TYPE_TEXT, + isBooleanValueType, + isNumericValueType, +} from '../valueTypes.js' import { AdaptiveClippingController } from './AdaptiveClippingController.js' import { addToTotalIfNumber } from './addToTotalIfNumber.js' import { parseValue } from './parseValue.js' @@ -744,7 +749,15 @@ export class PivotTableEngine { totalCell.valueType = currentValueType } - if (dxDimension?.valueType === VALUE_TYPE_NUMBER) { + // compute subtotals and totals for all numeric and boolean value types + // in that case, force value type of subtotal and total cells to NUMBER to format them correctly + // (see DHIS2-9155) + if ( + isNumericValueType(dxDimension?.valueType) || + isBooleanValueType(dxDimension?.valueType) + ) { + totalCell.valueType = VALUE_TYPE_NUMBER + dataFields.forEach((field) => { const headerIndex = this.dimensionLookup.dataHeaders[field] const value = parseValue(dataRow[headerIndex]) diff --git a/src/modules/renderValue.js b/src/modules/renderValue.js index 5e87629f1..9c2f1c763 100644 --- a/src/modules/renderValue.js +++ b/src/modules/renderValue.js @@ -47,7 +47,7 @@ const toFixedPrecisionString = (value, skipRounding) => { return value } - const precision = skipRounding ? 10 : value > -1 && value < 1 ? 2 : 1 + const precision = skipRounding ? 10 : 2 return value.toFixed(precision) }