Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
How to format a negative number in a WebGrid cell
posted

I'm trying to format a negative number in a Webgrid cell to show as (512.35)  instead of -512.35

How do I accomplish this?  I have tried Format = "($###,###.00)" which gives me ( ) around every number positive or negative.

Thanks in advance!

 

  • 65
    posted

    I just had the same problem. Below is the solution.

    Format = "$###,###.00;($###,###.00)"

    Brent

     

  • 1763
    posted

    I don't think you can use formatting to achieve that. Instead you could try using the Abs method of the Math class before rendering the value to the UltraGridCell.

    cell.Value = Math.Abs(-512.35);

    But this would work only if your grid is sort of 'Only for data display' purposes. If you want to recover that value again to save it back to database, then you might use some sort of flag to know that value was negative before rendering.