Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a string such as 5.7303333333e+02 to decimal in PowerShell?

I'm trying to convert strings such as 5.7303333333e+02 to the decimal type. I've tried using [decimal]::TryParse but the return value is false.

Is there a method similar to [datetime]::parseexact, or any clean way to convert these strings? Or am I going to have to parse out the e+02 and do that math separately?

like image 739
rtf Avatar asked Jun 06 '13 16:06

rtf


People also ask

How do I convert string to decimal in PowerShell?

[decimal]$string. Replace(",", ".")

How do you convert strings to decimals?

let stringVal = Convert. ToString decimalVal printfn $"The decimal as a string is {stringVal}."

How do I convert text to numbers in PowerShell?

Use [int] to Convert String to Integer in PowerShell The data type of $a is an integer . But when you enclose the value with " " , the data type will become string . To convert such string data type to integer, you can use [int] as shown below.


1 Answers

What about :

[int]"5.7303333333e+02"
[decimal]"5.7303333333e+02"
like image 137
JPBlanc Avatar answered Oct 03 '22 04:10

JPBlanc