0

I'm looking for a way to format a number:

<ss:Cell>
    <ss:Data ss:Type="Number">@importExportOption.StrikePrice</ss:Data>
</ss:Cell>

To a fixed number of decimal places. Where do I start?

user3488442
  • 89
  • 1
  • 1
  • 8

2 Answers2

0

Your question is actually independent of Excel. You just need to look at the different .ToString() overloads for numbers.

Specifically, you'd probably want something like: (taken from Kyle Rozendo's answer in the question here)

@string.Format("{0:N2}%", importExportOption.StrikePrice)
Community
  • 1
  • 1
krillgar
  • 12,596
  • 6
  • 50
  • 86
  • This seems good, but it gives me an file corrupt error when opening excel – user3488442 Apr 03 '14 at 14:32
  • I don't recognize the ``, etc syntax, and figured that if you give it a 2 place decimal string, everything would be fine. 1) Double check that if you don't include any of those numbers the file can open successfully (that the issue is really in these number formats). 2) If that does work, do you have any Number Format possibilities for the cells in whatever you're using to create the file? – krillgar Apr 03 '14 at 16:11
0

I didn't understand ss:Cell, but you can use this for number format (with rounding):

<ss:Cell>
    <ss:Data ss:Type="Number">@Math.Round(importExportOption.StrikePrice, 2)</ss:Data>
</ss:Cell>
Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90