sqlserver LN ;JavaScript LN ;C# LN ; sqlserver自然对数计算

 LN 即自然对数,是以常数e为底数的对数; 

一、数据库计算

sqlserver 2008没有直接给出LN函数;

但是给出了LOG,即对数(函数),若计算时以E为底,便就是自然对数(函数);

参考资料:

https://bbs.csdn.net/topics/360067339 --全是错误的

--正确思路来源:
https://bbs.csdn.net/topics/30261588

select Math.log( 10 ) / Math.log( Math.E )
虽然不适用于Sqlserver2008,但其拆分思想非常好;

--实验
select log(3/E) --报错:列名 'E' 无效。
--在E前面加数字1
select log(3/1E) --1.09861228866811
--计算器算得:1.0986122886681
select log(0.857142857/188.428571/1E)
-- -5.39286968138148
--Excel LN(0.857142857/188.428571
-- -5.392869681
--结论:sqlserver 计算正确
--应用
select -(0.857142857/188.428571) * log(0.857142857/188.428571/1E)

--0.0245316286250878

select PointBatchIDLeft,CatalogID, LOG( Individuals/Weight/1E )
from dbo.V_FishData

 

二、服务器端计算;

C# double y = Math.Log(x,Math.E);
 

三、前端计算;

 let num1 =getBaseLog(3,Math.E)
 console.log('num1',num1)
输出:num1 1.0986122886681096
 
//返回以 y 为底 x 的对数
function getBaseLog(x, y) {
  return Math.log(x) / Math.log(y);
};
 

四、其它常用计算:

平方运算

 double m;
 double n=Math.Pow(m,2.0);

平方根或开平方运算

System.Math.Sqrt(数字); 

保留两位小数

Math.Round(变量, 2);

 

posted @ 2020-03-19 10:02  hao_1234_1234  阅读(821)  评论(0)    收藏  举报