Skip to content

Commit eb5bc59

Browse files
committed
Added support for decimal and thousandth seperators #177
1 parent 21db3f1 commit eb5bc59

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

taskt/Core/Automation/Commands/MathCalculationCommand.cs

+38-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ public class MathCalculationCommand : ScriptCommand
2424
[Attributes.PropertyAttributes.Remarks("You can use known numbers or variables.")]
2525
public string v_InputValue { get; set; }
2626

27+
[XmlAttribute]
28+
[Attributes.PropertyAttributes.PropertyDescription("Optional - Indicate Thousand Seperator")]
29+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
30+
[Attributes.PropertyAttributes.InputSpecification("Enter the seperator used to identify decimal places")]
31+
[Attributes.PropertyAttributes.SampleUsage("")]
32+
[Attributes.PropertyAttributes.Remarks("Typically a comma or a decimal point (period)")]
33+
public string v_ThousandSeperator { get; set; }
34+
35+
[XmlAttribute]
36+
[Attributes.PropertyAttributes.PropertyDescription("Optional - Indicate Decimal Seperator")]
37+
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
38+
[Attributes.PropertyAttributes.InputSpecification("Enter the seperator used to identify decimal places")]
39+
[Attributes.PropertyAttributes.SampleUsage("")]
40+
[Attributes.PropertyAttributes.Remarks("Typically a comma or a decimal point (period)")]
41+
public string v_DecimalSeperator { get; set; }
2742

2843
[XmlAttribute]
2944
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive the math calculation")]
@@ -41,7 +56,8 @@ public MathCalculationCommand()
4156
this.CustomRendering = true;
4257

4358
this.v_InputValue = "(2 + 5) * 3";
44-
59+
this.v_DecimalSeperator = ".";
60+
this.v_ThousandSeperator = ",";
4561
}
4662

4763
public override void RunCommand(object sender)
@@ -51,10 +67,29 @@ public override void RunCommand(object sender)
5167

5268
try
5369
{
70+
var decimalSeperator = v_DecimalSeperator.ConvertToUserVariable(sender);
71+
var thousandSeperator = v_ThousandSeperator.ConvertToUserVariable(sender);
72+
73+
//remove thousandths markers
74+
variableMath = variableMath.Replace(thousandSeperator, "");
75+
76+
//check decimal seperator
77+
if (decimalSeperator != ".")
78+
{
79+
variableMath = variableMath.Replace(decimalSeperator, ".");
80+
}
81+
5482
//perform compute
5583
DataTable dt = new DataTable();
5684
var result = dt.Compute(variableMath, "");
5785

86+
//restore decimal seperator
87+
if (decimalSeperator != ".")
88+
{
89+
result = result.ToString().Replace(".", decimalSeperator);
90+
}
91+
92+
5893
//store string in variable
5994
result.ToString().StoreInUserVariable(sender, v_applyToVariableName);
6095
}
@@ -70,6 +105,8 @@ public override List<Control> Render(frmCommandEditor editor)
70105

71106
//create standard group controls
72107
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputValue", this, editor));
108+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ThousandSeperator", this, editor));
109+
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DecimalSeperator", this, editor));
73110

74111
RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_applyToVariableName", this));
75112
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_applyToVariableName", this).AddVariableNames(editor);

0 commit comments

Comments
 (0)