一.sql
CAST('123.456' as decimal) 将会得到 123(小数点后面的将会被省略掉)。
如果希望得到小数点后面的两位。
则需要把上面的改为
CAST('123.456' as decimal(38, 2)) ===>123.46
自动四舍五入了!
ALTER TRIGGER Trigger10
ON dbo.dd
FOR /* INSERT, UPDATE, DELETE */insert
AS
declare @a float
if(select bz from inserted)=0
begin
select @a=convert(float,interest) from loan where loanname='短期贷款'
end
else
begin
select @a=convert(float,interest) from loan where loanname='高利贷'
end
如果希望得到小数点后面的两位。
则需要把上面的改为
CAST('123.456' as decimal(38, 2)) ===>123.46
自动四舍五入了!
ALTER TRIGGER Trigger10
ON dbo.dd
FOR /* INSERT, UPDATE, DELETE */insert
AS
declare @a float
if(select bz from inserted)=0
begin
select @a=convert(float,interest) from loan where loanname='短期贷款'
end
else
begin
select @a=convert(float,interest) from loan where loanname='高利贷'
end
if(select ddxm from inserted)='借款金额'
begin
insert into dd
select inserted.projectid,inserted.marketid,inserted.marketyear+1,
inserted.marketquart,'还本付息', CAST(convert(float,inserted.ddje)*( 1+@a ) as decimal),inserted.bz,0 from inserted
end
begin
insert into dd
select inserted.projectid,inserted.marketid,inserted.marketyear+1,
inserted.marketquart,'还本付息', CAST(convert(float,inserted.ddje)*( 1+@a ) as decimal),inserted.bz,0 from inserted
end
二.C#
保留两位小数: string jzcsyl =(jlr / cs* 100).ToString ("0.00")+ "%";
三.JavaScript
/* * ForDight(Dight,How):数值格式化函数,Dight要 * 格式化的 数字,How要保留的小数位数。 */
1.function ForDight(Dight,How)
{
var Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
/* * ForDight(Dight,How):数值格式化函数,Dight要 * 格式化的 数字,How要保留的小数位数。 */
1.function ForDight(Dight,How)
{
var Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
2.<script>
var c=(parseFloat(document .getElementById("ddlxhf").value))*(parseFloat(document .getElementById("TextBox4").value));
document .getElementById ("TextBox5").value=Math .round( parseFloat(c)*100/100)
var c=(parseFloat(document .getElementById("ddlxhf").value))*(parseFloat(document .getElementById("TextBox4").value));
document .getElementById ("TextBox5").value=Math .round( parseFloat(c)*100/100)
</script>
本文转自叶子文文博客51CTO博客,原文链接http://blog.51cto.com/leafwf/186161如需转载请自行联系原作者
叶子文文