@@ -24,6 +24,21 @@ public class MathCalculationCommand : ScriptCommand
24
24
[ Attributes . PropertyAttributes . Remarks ( "You can use known numbers or variables." ) ]
25
25
public string v_InputValue { get ; set ; }
26
26
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 ; }
27
42
28
43
[ XmlAttribute ]
29
44
[ Attributes . PropertyAttributes . PropertyDescription ( "Please select the variable to receive the math calculation" ) ]
@@ -41,7 +56,8 @@ public MathCalculationCommand()
41
56
this . CustomRendering = true ;
42
57
43
58
this . v_InputValue = "(2 + 5) * 3" ;
44
-
59
+ this . v_DecimalSeperator = "." ;
60
+ this . v_ThousandSeperator = "," ;
45
61
}
46
62
47
63
public override void RunCommand ( object sender )
@@ -51,10 +67,29 @@ public override void RunCommand(object sender)
51
67
52
68
try
53
69
{
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
+
54
82
//perform compute
55
83
DataTable dt = new DataTable ( ) ;
56
84
var result = dt . Compute ( variableMath , "" ) ;
57
85
86
+ //restore decimal seperator
87
+ if ( decimalSeperator != "." )
88
+ {
89
+ result = result . ToString ( ) . Replace ( "." , decimalSeperator ) ;
90
+ }
91
+
92
+
58
93
//store string in variable
59
94
result . ToString ( ) . StoreInUserVariable ( sender , v_applyToVariableName ) ;
60
95
}
@@ -70,6 +105,8 @@ public override List<Control> Render(frmCommandEditor editor)
70
105
71
106
//create standard group controls
72
107
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 ) ) ;
73
110
74
111
RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_applyToVariableName" , this ) ) ;
75
112
var VariableNameControl = CommandControls . CreateStandardComboboxFor ( "v_applyToVariableName" , this ) . AddVariableNames ( editor ) ;
0 commit comments