ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Decimal question in variable? (https://www.excelbanter.com/excel-programming/409271-decimal-question-variable.html)

Jean

Decimal question in variable?
 
Hi,
I would like to know if it exists a function to round up or down a three or
more decimal at only two,
I am not talking about the content of a cell but at the content of a variable
Ex: B = 13.34567
A = 13.35
C = A - B
I would like In this Example the result of C to be 0.
In fact I would like round up B to be 13.35.
or 13.34 if B was 13.34458

Thank you very much

Jean


Rick Rothstein \(MVP - VB\)[_1713_]

Decimal question in variable?
 
You can use the Round function to do what is called Banker's Rounding (if
number ends in 5 and is being rounded to the previous decimal position, the
value is rounded to the previous even digit) or Format to do what I consider
"normal" rounding (if a number ends in 5 and is being rounded to the
previous decimal position, it always rounded upward).

B = 13.34567
A = 13.3
C = Round(A - B, 2) <<<or C = Format(A - B, "0.00")

If you really want the 0 value to be 0 and not 0.00, the Format version can
be changed to this...

C = Format(A - B, "0.00;;0")

Rick



"jean" wrote in message
...
Hi,
I would like to know if it exists a function to round up or down a three
or
more decimal at only two,
I am not talking about the content of a cell but at the content of a
variable
Ex: B = 13.34567
A = 13.35
C = A - B
I would like In this Example the result of C to be 0.
In fact I would like round up B to be 13.35.
or 13.34 if B was 13.34458

Thank you very much

Jean




All times are GMT +1. The time now is 02:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com