Arturo Martinez Arturo Martinez - 1 month ago 10
C# Question

Stuck With if Statement

This is my Code:

if (haveDataDay) {
@if (valueDateDay <=100) {
valueDateDay.ToString();
} else if (valueDateDay > 100) {
@valueDateDay.ToString(valueDateDay % 1 == 0 ? "N0" : "C2")
}
} else {
@this.FP("lbl.loader.nodata")
}


Im trying to check if "valueDateDay" has a decimal value of "100 or less" then only change it to string to this line:

valueDateDay.ToString();


and if the "valueDateDay" is bigger than 100 then it need to check this statement and convert it to string:

@valueDateDay.ToString(valueDateDay % 1 == 0 ? "N0" : "C2") }


and if the "valueDateDay" value has no data or equals 0 then get0s to this line:

else
{ @this.FP("lbl.loader.nodata") }


however when i run my code my values bigger than 100 are asigned correctly but the values of 100 or less are not saved going directly to :

else
{ @this.FP("lbl.loader.nodata") }


what am i doing wrong?

Answer

Your braces are formatted the wrong way, so the else is out of the if-else continuum.

 if (haveDataDay) {
    if (valueDateDay <=100 && valueDataDay > 0) { 
        valueDateDay.ToString();
    } else if (valueDateDay > 100) {
        valueDateDay.ToString(valueDateDay % 1 == 0 ? "N0" : "C2")
    } else {
        this.FP("lbl.loader.nodata")
    }
}

Also, valueDateDay smaller or equal to 0 will go in the first loop, so add the condition that it is greater than zero: valueDateDay <=100 && valueDataDay > 0.