# Help Converting String Fractions to Doubles

**URL:** <https://forums.powershell.org/t/help-converting-string-fractions-to-doubles/15001>\
**Category:** PowerShell Help\
**Created:** [September 24, 2020, 8:18pm UTC](https://forums.powershell.org/t/help-converting-string-fractions-to-doubles/15001 "2020-09-24T20:18:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caidenblock](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/caidenblock/32/57_2.png) [@caidenblock](https://forums.powershell.org/u/caidenblock)\
**Post date:** [September 24, 2020, 8:18pm UTC](https://forums.powershell.org/t/help-converting-string-fractions-to-doubles/15001/1 "2020-09-24T20:18:17Z")

</div>

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:

```
$string = "15/2"
$double = [double]$string
Write-Host $double
```

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?

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 8, 2020, 11:45pm UTC](https://forums.powershell.org/t/help-converting-string-fractions-to-doubles/15001/2 "2020-10-08T23:45:25Z")

</div>

“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.

```
$string = "15/2"
[double]$double = $string.Split('/')[0]/$string.Split('/')[1]
```

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/help-converting-string-fractions-to-doubles/15001/3 "2024-05-16T20:28:44Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


