Adding functions to Standard Library
This commit is contained in:
parent
808d4ca420
commit
4a21ff3d46
39 changed files with 1465 additions and 51 deletions
37
src/StandardLibrary/Functions/Rounding/Round.cs
Normal file
37
src/StandardLibrary/Functions/Rounding/Round.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
namespace CSMic.StandardLibrary.Functions.Rounding
|
||||
{
|
||||
public class Round : FunctionBase, ICodedFunction
|
||||
{
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "round";
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<FunctionArgument> ExpectedArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new FunctionArgument("value", FunctionValue.NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
public FunctionValue Execute(params FunctionArgument[] args)
|
||||
{
|
||||
return Execute(args, (_args) =>
|
||||
{
|
||||
var inputValue = _args[0].Value;
|
||||
decimal value = Convert.ToDecimal(inputValue.Value);
|
||||
var inputPrecision = _args[1].Value;
|
||||
decimal precision = Convert.ToDecimal(inputValue.Value);
|
||||
precision = Math.Round(precision);
|
||||
int precisionInt = Convert.ToInt32(precision);
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, Math.Round(value, precisionInt));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue