Skip to main content Link Search Menu Expand Document (external link)

sign() : Sign of Number


On this page

Summary

Get the sign of a number (-1, 0, or 1).

Signature

sign(value)

Parameters

Parameter Type Required Description
value Number Yes The number to check

Returns

Type: Integer

  • -1 if value is negative
  • 0 if value is zero
  • 1 if value is positive

Examples

Check Sign


  <p class="positive">Credit: $</p>

  <p class="negative">Debit: $</p>

  <p>Zero balance</p>

Data:

doc.Params["model"] = new {
    balance = -150.00m
};

Output:

<p class="negative">Debit: $150</p>

Profit/Loss Indicator


  <tr>
    <td></td>
    <td> %</td>
  </tr>

Data:

doc.Params["model"] = new {
    accounts = new[] {
        new { name = "Account A", change = 5.2 },
        new { name = "Account B", change = -3.1 }
    }
};

Output:

<tr>
  <td>Account A</td>
  <td>▲ 5.2%</td>
</tr>
<tr>
  <td>Account B</td>
  <td>▼ 3.1%</td>
</tr>

Direction Indicator

<p>Trend: </p>

Notes

  • Returns integer: -1, 0, or 1
  • Useful for determining direction
  • Often used with abs() for magnitude
  • Common in financial and trend displays

See Also