tf_round_number()

Purpose

Rounds a double-precision number to the specified accuracy

Old name

#define round_number tf_round_number

Syntax

double tf_round_number(number, decimal_places)

Parameters

double number

Number to round

 

int decimal_places

Required accuracy, as a number of decimal places

Description

The tf_round_number() function rounds the given number to the specified number of decimal places.

If the value of the digit in the decimal place after that given by the parameter decimal_places is greater than or equal to 5, the previous digit is incremented by 1. For example, the call:

tf_round_number(3.149, 2);

returns 3.15. The call:

tf_round_number(3.999, 2)

returns 4.00.

Return values

Returns the rounded double-precision number

See also

tf_trunc_number()

Example

/*
C Functions Reference Manual
----------------------------
Filename: TF_ROUND.C
Example: tf_round_number
Purpose: illustrates the library function
tf_round_number
*/

/*
#db salesord
#c
#end
*/
#include "dp4.h"
#include "tf_round.h"
/* generate this file by running LIBMAKE */
void process()
{
double n = 0.0;
map_draw(1,RETAIN);
for (;;)
{
if (askf_n(1,1,&n))
/* get number from user */
break; /* break if escape */
show_n(1,2,tf_round_number(n,2));
/* display round in field 2 */
show_n(1,3,tf_trunc_number(n,2));
/* display trunc in field 3 */
}
}