Commit 369b540a authored by Robert Wilhelm's avatar Robert Wilhelm Committed by Alexandre Julliard

vbscript: Handle numdecimalplaces argument in Round().

parent 0a7f5646
......@@ -3153,32 +3153,47 @@ static HRESULT Global_MonthName(BuiltinDisp *This, VARIANT *args, unsigned args_
return return_bstr(res, ret);
}
static HRESULT Global_Round(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
static HRESULT Global_Round(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
{
double n;
int decimal_places = 0;
double d;
HRESULT hres;
TRACE("%s\n", debugstr_variant(arg));
TRACE("%s %s\n", debugstr_variant(args), args_cnt == 2 ? debugstr_variant(args + 1) : "0");
assert(args_cnt == 1 || args_cnt == 2);
if(!res)
return S_OK;
switch(V_VT(arg)) {
if(args_cnt == 2) {
if (V_VT(args + 1) != VT_ERROR) {
hres = to_int(args + 1, &decimal_places);
if (FAILED(hres))
return hres;
}
}
switch(V_VT(args)) {
case VT_I2:
case VT_I4:
case VT_BOOL:
*res = *arg;
*res = *args;
return S_OK;
case VT_R8:
n = V_R8(arg);
d = V_R8(args);
break;
default:
hres = to_double(arg, &n);
hres = to_double(args, &d);
if(FAILED(hres))
return hres;
}
return return_double(res, round(n));
hres = VarR8Round(d, decimal_places, &d);
if(FAILED(hres))
return hres;
return return_double(res, d);
}
static HRESULT Global_Escape(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
......@@ -1090,6 +1090,29 @@ TestRound "2", 2, "VT_R8"
TestRound true, true, "VT_BOOL"
TestRound false, false, "VT_BOOL"
Sub TestRound2(val, decnum, exval, vt)
Call ok(Round(val, decnum) = exval, "Round(" & val & " , " & decnum & ") = " & Round(val, decnum))
Call ok(getVT(Round(val, decnum)) = vt, "getVT(Round(" & val & " , " & decnum & ")) = " & getVT(Round(val, decnum)))
End Sub
TestRound2 3, 0, 3, "VT_I2"
TestRound2 3, 1, 3, "VT_I2"
TestRound2 3.3, 0, 3, "VT_R8"
TestRound2 3.8, 0, 4, "VT_R8"
TestRound2 3.5, 0, 4, "VT_R8"
TestRound2 -3.3, 0, -3, "VT_R8"
TestRound2 -3.5, 0, -4, "VT_R8"
TestRound2 3.3, 1, 3.3, "VT_R8"
TestRound2 3.8, 1, 3.8, "VT_R8"
TestRound2 3.5, 1, 3.5, "VT_R8"
TestRound2 -3.3, 1, -3.3, "VT_R8"
TestRound2 -3.5, 1, -3.5, "VT_R8"
TestRound2 "2", 1, 2, "VT_R8"
TestRound2 true, 0, true, "VT_BOOL"
TestRound2 false, 0, false, "VT_BOOL"
TestRound2 true, 1, true, "VT_BOOL"
TestRound2 false, 1, false, "VT_BOOL"
if isEnglishLang then
Call ok(WeekDayName(1) = "Sunday", "WeekDayName(1) = " & WeekDayName(1))
Call ok(WeekDayName(3) = "Tuesday", "WeekDayName(3) = " & WeekDayName(3))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment