diff --git a/reference/intl/numberformatter/set-attribute.xml b/reference/intl/numberformatter/set-attribute.xml index dcc64e69d310..075f37aaa8f7 100644 --- a/reference/intl/numberformatter/set-attribute.xml +++ b/reference/intl/numberformatter/set-attribute.xml @@ -116,6 +116,45 @@ Digits: 2 1.234.567,89 ]]> + + Using <constant>NumberFormatter::ROUNDING_MODE</constant> to truncate values + + By default, NumberFormatter rounds values. Using + NumberFormatter::ROUND_DOWN as the + NumberFormatter::ROUNDING_MODE truncates + the value to the specified number of fraction digits without rounding. + + +setAttribute(NumberFormatter::FRACTION_DIGITS, 2); + +echo "Default rounding mode:\n"; +echo $fmt->format(3.789), "\n"; // 3.79 (rounded up) +echo $fmt->format(3.781), "\n"; // 3.78 (rounded down) + +$fmt->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_DOWN); + +echo "\nWith ROUND_DOWN (truncate):\n"; +echo $fmt->format(3.789), "\n"; // 3.78 (truncated) +echo $fmt->format(3.781), "\n"; // 3.78 (truncated) +?> +]]> + + &example.outputs; + + + +