Hakan OTAL
10/13/2003 1:04:00 PM
Thanks Dino Chiesa for your opinion...
"Dino Chiesa [Microsoft]" <dinoch@online.microsoft.com>, iletide þunu yazdý
news:%231pkFMpjDHA.360@TK2MSFTNGP12.phx.gbl...
> You did not mention the language you prefer to work in.
> One way to do this is to use the Jscript library function "eval". I think
> this was also present in VB6 (but not in VB.NET?) .
>
> Eg, define a JScript.NET module like so;
> ===============================
> import System.Console;
> package Ionic
> {
> class JsUtil
> {
> public static function Eval(expr : String) : String
> {
> System.Console.WriteLine("expression: {0}", expr); // debug only
> var result : String = eval(expr);
> System.Console.WriteLine("result: {0}", result); // debug only
> return result;
> }
> }
> }
> ==================
> Compile this JScript.NET code into a DLL.
>
> Call if from C# or VB, like so:
> ============================
> public class Test {
> public static void Main() {
> string str1= "((10*80) / 100)";
> Ionic.JsUtil.Eval( str1 );
> string str2= "(240/80)";
> Ionic.JsUtil.Eval(str2);
> Ionic.JsUtil.Eval(str1 + " - " + str2);
> }
> }
> =========================
>
>
> To compile this you would need to do something like so:
> $(_JSC) $(_CS_DLL_FLAGS) /out:Evallib.dll Eval.js
> $(_CSC) $(_CS_EXE_FLAGS) /r:Evallib.dll /r:Microsoft.JScript.dll
> /out:Eval.exe Eval.cs
>
>
>
> --
> Dino Chiesa
> Microsoft Developer Division
> d i n o c h @ o n l i n e . m i c r o s o f t . c o m
>
>
>
> "Hakan OTAL" <hakanotal@yahoo.com> wrote in message
> news:uICc%23jnjDHA.1004@tk2msftngp13.phx.gbl...
> how can i convert an expression to decimal that i created at runtime
>
> str1 = ((10*80) / 100)
> str2 = (240/80)
>
> str3 = ((10*80) / 100) - (240/80)
> (800 / 100) - 6
> 8 - 6
> 2
>
> decimal_value = 2
>
> i want to see decimal result...
>
>