【发布时间】:2019-10-14 14:00:35
【问题描述】:
我在 Excel 工作表中使用了一个宏来为特殊计算器制作自定义舍入函数。我想将计算器表上传到我的谷歌驱动器,以便我可以将其作为资源共享。但是,excel 语言无法转换为 Google Apps 脚本语言,我不知道如何调整它。
我不是代码专家,因为我从 excel 中复制了基本代码并稍作调整,可能很幸运能够使其正常工作。但我试图将代码翻译成在谷歌应用程序脚本中工作,但从来没有让它在没有错误的情况下运行。
这是给我一个成功函数的excel代码。
Function pokeRound(pValue As Double) As Double
Dim LWhole As Long
Dim LFraction As Double
'Retrieve integer part of the number
LWhole = Int(pValue)
'Retrieve the fraction part of the number
LFraction = pValue - LWhole
If LFraction <= 0.5 Then
pokeRound = LWhole
Else
pokeRound = Round(pValue, 0)
End If
End Function
这是我的翻译尝试失败了
function pokeRound() {
// Retrieve integer part of the number
var LWhole = (pValue);
// Retrieve the fraction part of the number
var LFraction = pValue - LWhole;
If (LFraction <= 0.5)
pokeRound = LWhole;
Else
(pokeRound = Round(pValue, 0));
};
这个函数的结果是一个自定义的舍入方法。正常四舍五入意味着 88.5 舍入到 89。此函数将 88.5 舍入到 88 和 88.51 到 89 舍入。谁能帮我翻译它以在 Google Apps 脚本中工作?
【问题讨论】:
-
欢迎来到 StackOverFlow,请借此机会参加 tour 并学习如何使用 How to Ask 和 minimal reproducible example。
标签: excel vba google-apps-script google-sheets google-sheets-macros