- This topic has 1 reply, 2 voices, and was last updated 2 weeks, 3 days ago by
September 25, 2020 at 1:48 am #258853ParticipantTopics: 2Replies: 0Points: 11Rank: Member
Hello! I’m pretty new to PowerShell, but I can’t find an answer to this.
I’m trying to convert one of my FFmpeg cmd scripts to PowerShell, but I can’t figure this out for the life of me
FFprobe responds to a query with a fraction in string format, how can I get that into a double?
This isn’t possible in the command line, as there’s no floating-point support there, there was a workaround using visual basic scripts.
I was hoping that wasn’t needed in PS, but I can’t find a way to solve this seemingly simple problem.
code:PowerShell123$string = "15/2"$double = [double]$stringWrite-Host $double
<p class=””>Cannot convert value “15/2” to type “System.Double”. Error: “Input string was not in a correct format.” FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle</p>
Is there a way to do this in PowerShell?
October 9, 2020 at 5:15 am #262037ParticipantTopics: 1Replies: 342Points: 326Rank: Contributor
“15/2” in your example is a String literal and is not evaluated. In lieu of writing a parser to perform the maths, I would suggest splitting the string on the division operator and then dividing the two numbers.PowerShell12$string = "15/2"[double]$double = $string.Split('/')/$string.Split('/')
- You must be logged in to reply to this topic.