Oracle 舍入问题
我使用此代码将十进制值向下舍入为 25 的下一个倍数。 即,如果值为 33.60,则应舍入为 33.50
create or replace
PROCEDURE "TEST1" (PQUERY IN VARCHAR2) as
prNspValue number(14,2) :='';
p_percentage_Value number(4,2) :='';
begin
prNspValue:=33.60;
dbms_output.put_line(prNspValue);
p_percentage_Value:=substr(prNspValue,instr(prNspValue,'.')+1,length(prNspValue));
dbms_output.put_line(p_percentage_value);
p_percentage_Value:=p_percentage_Value-mod(p_percentage_Value,25);
dbms_output.put_line(p_percentage_value);
if(p_percentage_Value!=0)then
prNspValue:=substr(prNspValue,1,instr(prNspValue,'.'))+p_percentage_Value/100;
else
prNspValue:=substr(prNspValue,1,instr(prNspValue,'.'));
end if;
dbms_output.put_line(prNspValue);
end;
,但问题是当值为 33.60 时,它会被视为 33.6。所以它四舍五入为 33.0。 我该如何更正此代码?
I am using this code to round down the decimal value to the next multiple of 25.
ie if value is 33.60 it should round to 33.50
create or replace
PROCEDURE "TEST1" (PQUERY IN VARCHAR2) as
prNspValue number(14,2) :='';
p_percentage_Value number(4,2) :='';
begin
prNspValue:=33.60;
dbms_output.put_line(prNspValue);
p_percentage_Value:=substr(prNspValue,instr(prNspValue,'.')+1,length(prNspValue));
dbms_output.put_line(p_percentage_value);
p_percentage_Value:=p_percentage_Value-mod(p_percentage_Value,25);
dbms_output.put_line(p_percentage_value);
if(p_percentage_Value!=0)then
prNspValue:=substr(prNspValue,1,instr(prNspValue,'.'))+p_percentage_Value/100;
else
prNspValue:=substr(prNspValue,1,instr(prNspValue,'.'));
end if;
dbms_output.put_line(prNspValue);
end;
but the problem is when the value is 33.60 it is taken as 33.6. so it is rounding it to 33.0.
How can i correct this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接使用round函数
FLOOR(your_number*4)/4
:you can use the round function directly
FLOOR(your_number*4)/4
: