Hey everyone! I'm running into a bit of a snag trying to convert strings to doubles in PowerShell. For example, I can successfully convert "82,85" without any issues, but when I try to convert "2 533,92", I get an error. It seems like the spaces or commas are messing it up. Is there a reliable way to make sure the conversion works correctly for different formats? Any tips would be greatly appreciated!
2 Answers
Yeah, the correct way is definitely to use the culture info like the other comment mentioned. But if you're unsure of the culture, you can try a workaround by removing all the spaces first:
```powershell
[double]::Parse($('2 533,92' -replace 's'))
``` That should do the trick!
The main issue is the format of your string. You should specify the culture when parsing numbers so that PowerShell knows how to interpret the formatting. For example, you can use this:
```powershell
[double]::Parse("2 533,92", [cultureinfo]::new("fr-FR"))
```
If your PC is set to that culture, you can just use:
```powershell
[cultureinfo]::CurrentCulture
```
It actually works perfectly! Thanks for the tip!