1

I am having a problem evaluating Negative numbers with Powershell. In this example -0.36 should have been less than -0.01. So $Bad_Note should be 0 and not 1

$Note = "0, -0.36"
$Markup_Discount = ($Note -split ',')[1].trim()
$Markup_Discount 
$Bad_Note = 0
if ($Markup_Discount -gt -0.01) {$Bad_Note = 1}
$Bad_Note

1 Answer 1

4

I think you are trying to compare a [string] with a [float]. Just add [float] before the string to convert this one in float (but take care you need to be sure it will work).

Like this :

$Note = "0, -0.36"
$Markup_Discount = [float]($Note -split ',')[1].trim()
$Markup_Discount 
$Bad_Note = 0
if ($Markup_Discount -gt -0.01) {$Bad_Note = 1}
$Bad_Note

Or this one (as you want) :

$Note = "0, -0.36"
$Markup_Discount = ($Note -split ',')[1].trim()
$Markup_Discount 
$Bad_Note = 0
if ([float]$Markup_Discount -gt -0.01) {$Bad_Note = 1}
$Bad_Note

Have fun :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.