ShortCode

[tws_round]

This ShortCode is part of the ToolWine ShortCodes Plugin. Download and Install the ToolWine ShortCodes Plugin to use it. Note that the Plugin requires Toolset Types and Views (or Blocks) installed and active.

The [tws_round] ShortCode can be used to round up or down any float value passed as content to the ShortCode. It is an enclosing ShortCode, so anything “wrapped” within it will be rounded up or down (well, as long it is numbers).

Attributes:

  • roundint [number of decimals to round after comma] default 2
  • dirconst [a valid PHP Round Constant] default PHP_ROUND_HALF_UP
    Possible values for dir
PHP_ROUND_HALF_UPRounds val away from zero when it is half way there, making 1.5 into 2 and -1.5 into -2.
PHP_ROUND_HALF_DOWNRounds val towards zero when it is half way there, making 1.5 into 1 and -1.5 into -1.
PHP_ROUND_HALF_EVENRounds val towards the nearest even value when it is half way there, making both 1.5 and 2.5 into 2.
PHP_ROUND_HALF_ODDRounds val towards the nearest odd value when it is half way there, making 1.5 into 1 and 2.5 into 3.

Example

//Round DOWN a float value to no decimals after comma. Produces number 9
[round_values round="0" dir="PHP_ROUND_HALF_DOWN"]9.5[/round_values] 
//Round UP a float value to 2 decimals. Produces 9.85
[round_values round="2"]9.833333333333[/round_values]