Help Converting String Fractions to Doubles

Welcome Forums General PowerShell Q&A Help Converting String Fractions to Doubles

Viewing 1 reply thread
  • Author
    Posts
    • #258853
      Participant
      Topics: 2
      Replies: 0
      Points: 11
      Rank: 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:

      Results in
      <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?

      • This topic was modified 1 month ago by CaidenBlock86. Reason: formatted error on accident
      • This topic was modified 4 weeks ago by grokkit.
    • #262037
      Participant
      Topics: 1
      Replies: 342
      Points: 326
      Helping Hand
      Rank: 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.

       

       

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.