rounding_20functions
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rounding_20functions [2018/03/31 13:19] – external edit 127.0.0.1 | rounding_20functions [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, June 2016//\\ \\ If you want to **round** a numeric value to a specific number of decimal places or significant figures there are a number of ways in which this can be achieved. The most flexible way is to use the [[http:// | //by Richard Russell, June 2016//\\ \\ If you want to **round** a numeric value to a specific number of decimal places or significant figures there are a number of ways in which this can be achieved. The most flexible way is to use the [[http:// | ||
+ | <code bb4w> | ||
DEF FNround_dp(n, | DEF FNround_dp(n, | ||
LOCAL @% | LOCAL @% | ||
Line 11: | Line 12: | ||
@% = & | @% = & | ||
= STR$(n) | = STR$(n) | ||
+ | </ | ||
It is perhaps worth emphasising that the concept of rounding to a certain number of digits applies only to decimal numbers, which is why the above functions return strings. BBC BASIC holds numeric values internally in binary, so you cannot meaningfully refer to them as being rounded to a certain number of decimal digits. | It is perhaps worth emphasising that the concept of rounding to a certain number of digits applies only to decimal numbers, which is why the above functions return strings. BBC BASIC holds numeric values internally in binary, so you cannot meaningfully refer to them as being rounded to a certain number of decimal digits. |
rounding_20functions.1522502378.txt.gz · Last modified: 2024/01/05 00:16 (external edit)