Tips  |  Documentation  |  Archive
Change how totals are rounded

    
	// If your customers torment you with frequent changes in business logic,
	// in particular, by changing the way of rounding the totals, you can
	// use this function. Take care to
	// gi_scale and gb_buh_round_regim variables were changed in configuration mode
	// your application





	//// Function buhround (dec_sum, 10000/100/10/1 /, TRUE / FALSE)
	//// --------- Sample call -------------------
	//// decimal {4} ld_mysum
	//// ...
	//// ld_mysum = buhround (ld_mysum, gi_scale, gb_buh_round_regim)
	//// -----------------------------------------
	//// Round up or according to the usual rules to the specified precision
	//// d_summ - initial amount> = 0
	//// i_scale - rounding precision
	//// = 10000 - up to 0.0001 kopecks, cents, pfening ...
	//// 100 - up to 0.01 ...
	//// 10 - up to 10 ....
	//// 1 - to the ruble, dollar, mark ...
	//// b_buhregim - rounding mode
	//// false - according to the usual rules
	//// true - up
	//// rounded sum - returns or (-1 - error)
	
	IF (i_scale100 AND i_scale1)  
	OR d_summ
	decimal{4} ld_sumstore
	
	CHOOSE CASE b_buhregim
	CASE TRUE
	ld_sumstore = d_summ * i_scale
	d_summ = Truncate(ld_sumstore, 0)
	
	IF ld_sumstore - d_summ > 0 THEN
	d_summ = d_summ + 1
	END IF
	
	d_summ = d_summ / i_scale
	
	CASE FALSE
	d_summ = Round(d_summ * i_scale, 0)/i_scale
	CASE ELSE
	
	END CHOOSE
	
	return d_summ