Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
@echo offclssetlocal echo wscript.echo eval(wscript.arguments(0))>%temp%\eval.vbsset a=22set b=7set calc=%a%/%b%call :calculateset Pi=%result%echo %Pi%del %temp%\eval.vbsexit /b:calculatefor /f %%1 in ('cscript //nologo %temp%\eval.vbs "%calc%"') do ( set result=%%1)
Atn(1)*4
The following script returns Pi with 14 decimal places.
c:\>for /f %A in ('cscript //nologo eval.vbs "round(4*ATN(1),5)"') do @echo %A3.14159
Petroutsos writes, "The topic of printing with Visual Basic is a non-trivial topic...Mastering Visual Basic .NET [Paperback]
C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,9)"') do @echo %A3.142857143
Another option for you as well.Code: [Select]C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,9)"') do @echo %A3.142857143
Does not work for me.
C:\Users\Squash\batch>echo wscript.echo eval(wscript.arguments(0))>eval.vbsC:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,5)"') do @echo %A3.14286C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(4*ATN(1),5)"') do @echo %A3.14159C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(4*ATN(1),9)"') do @echo %A3.141592654
Function Truncate(ByVal Value,Byval NumDigits) Dim digitfactor digitfactor = (10^numdigits) Truncate = Fix(Value * digitfactor)/digitfactorEnd Function
for /f %A in ('cscript //nologo eval.vbs "Fix(Atn(1)*4*(10^4))/(10^4)"') do @echo %A
Eval() in VBscript only takes a single argument. To force it to be only two decimal places takes something additional.
C:\>eval round(4*(1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)-(1/15)+(1/17)-(1/19)+(1/21)-(1/23)+(1/25)),2)3.22
No it doesn't. This has already been shown! The argument can be more or less any string....
Format a number with a currency symbol.Syntax FormatCurrency(number [,DecimalPlaces [,IncludeLeadingZero [,UseParenthesis [, GroupDigits]]]] )Key number The number to format. DecimalPlaces Number of digits to display after the decimal point. IncludeLeadingZero Include a leading zero for numbers <1 and > -1 UseParenthesis Show negative numbers in Parentheis (500) = -500 GroupDigits Group large numbers with commas (or the regional delimiter)ExampleSet intDemo = 150000.56WScript.Echo FormatCurrency(intDemo,1)“The best way to destroy the capitalist system is to debauch the currency. By a continuing process of inflation, governments can confiscate, secretly and unobserved, an important part of the wealth of their citizens” - John Maynard Keynes - W. Edwards Deming
Pi is not longer the issue. But my choice is banana crane.
But eval() in VBS takes one argument. In the syntax it says one argument. The argument and be an expression or a function
My impression was the he OP wanted something simple where the number of decimals could be specifically given.Suppose there was a thing called fancyeval() that take a number and a string. and returns a string
C:\>Eval FormatNumber(23.1,2)23.10
There is a data type for currency, but I do not think it is in VBS.
C:\>eval FormatCurrency(23.1,2)£23.10
In VB 6, the Currency data type was designed for financial calculations. But Microsoft decided that it just didn't do the job so they dropped it and now we have the Decimal data type in VB.NET.This article tells you all about the Decimal data type in VB.NET: What's new, what works and what doesn't. Like the rest of .NET, Decimal is far more powerful. And like the rest of .NET, there are hidden traps. Just to get started, here's one you might not have seen before:If you just happened to use the VB 6 Currency data type to create a record in a file using a structure like this one ...Private Type FileRecord Field1 As Integer CurrencyField As Currency Field2 As DoubleEnd Type
Salmon Trout, Are you British? You have little sense of humor.
The quote below is not code.QuoteC:\>Eval FormatNumber(23.1,2)23.10
Wscript.echo eval(WScript.Arguments(0))
Wscript.echo eval("FormatNumber(23.1,2)")
Wscript.echo FormatNumber(23.1,2)
Not sure what you're trying to say there Geek.
Not sure what you're trying to say there Geek
Code should be ready to o code. So the user can just copy and paste it into whatever project he is doing.
WScript.Echo FancyEval("Left$(""test"",2)"),2)
If this is of interest, click on the ink above.The only point I want to make is that round() is not the way to format When doing financial things, the correct format is very important