File tree 3 files changed +34
-3
lines changed
EPPlusTest/FormulaParsing/IntegrationTests
3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,18 @@ public static IOperator Exp
198
198
}
199
199
}
200
200
201
+ private static string CompileResultToString ( CompileResult c )
202
+ {
203
+ if ( c != null && c . IsNumeric )
204
+ {
205
+ if ( c . ResultNumeric is double d )
206
+ {
207
+ return d . ToString ( "G15" ) ;
208
+ }
209
+ }
210
+ return c . ResultValue . ToString ( ) ;
211
+ }
212
+
201
213
public static IOperator Concat
202
214
{
203
215
get
@@ -206,8 +218,8 @@ public static IOperator Concat
206
218
{
207
219
l = l ?? new CompileResult ( string . Empty , DataType . String ) ;
208
220
r = r ?? new CompileResult ( string . Empty , DataType . String ) ;
209
- var lStr = l . Result != null ? l . ResultValue . ToString ( ) : string . Empty ;
210
- var rStr = r . Result != null ? r . ResultValue . ToString ( ) : string . Empty ;
221
+ var lStr = l . Result != null ? CompileResultToString ( l ) : string . Empty ;
222
+ var rStr = r . Result != null ? CompileResultToString ( r ) : string . Empty ;
211
223
return new CompileResult ( string . Concat ( lStr , rStr ) , DataType . String ) ;
212
224
} ) ;
213
225
}
Original file line number Diff line number Diff line change @@ -23,7 +23,16 @@ public class ExpressionConverter : IExpressionConverter
23
23
public StringExpression ToStringExpression ( Expression expression )
24
24
{
25
25
var result = expression . Compile ( ) ;
26
- var newExp = new StringExpression ( result . Result . ToString ( ) ) ;
26
+ string toString ;
27
+ if ( result . DataType == DataType . Decimal )
28
+ {
29
+ toString = result . ResultNumeric . ToString ( "G15" ) ;
30
+ }
31
+ else
32
+ {
33
+ toString = result . Result . ToString ( ) ;
34
+ }
35
+ var newExp = new StringExpression ( toString ) ;
27
36
newExp . Operator = expression . Operator ;
28
37
return newExp ;
29
38
}
Original file line number Diff line number Diff line change @@ -59,5 +59,15 @@ public void DivByZeroShouldReturnError()
59
59
var result = _ws . Calculate ( "10/0 + 3" ) ;
60
60
Assert . AreEqual ( DivByZero , result ) ;
61
61
}
62
+
63
+ [ TestMethod ]
64
+ public void ConcatShouldUseFormatG15 ( )
65
+ {
66
+ var result = _ws . Calculate ( "14.000000000000002 & \" %\" " ) ;
67
+ Assert . AreEqual ( "14%" , result ) ;
68
+
69
+ result = _ws . Calculate ( "\" %\" & 14.000000000000002" ) ;
70
+ Assert . AreEqual ( "%14" , result ) ;
71
+ }
62
72
}
63
73
}
You can’t perform that action at this time.
0 commit comments