Datatype conversion?

Hi,

How do i convert a string value to a currency value? I get a value as "$5,416,964,702" i must be able to set it as currency/float but display the same. How can i accomplish this?

Regards,

Soumya.

You can try:

string a = "$5,416,964,702";
double b = double.Parse(a.Substring(1));

cell.PutValue(b);

cell.Style.Number = 5;

yes, this code converts the string to double. But what i want is, conversion to double and display as "$5,416,964,702", but with the above code , it gets bound as 5416964702. Where as the display must be a currency but the value will be a double. I am attaching a sample excel that i created. If u click on any of the cells that displays currency, the value is shown in numbers. Can this feature be implemented using aspose?

In MS Excel, a currency is saved as double and format as currency. If you wish that the formula bar also shows this, you only need to use following code:

cell.PutValue("$5,416,964,702");

However, in this situation, it's saved as string instead of number in Excel file.

thanks, i understand what you say. We’ll i used

cells[startRow + 2, 5].Style.Number = 8; for displaying the currency wiht the symbol. It works. The only problem that i have now is that insted of '$' i get then symbol of the currency 'yen'. Do i need to make some custom settings? I tried setting from 1 to 0 for Style. number, and i dint find any theat would give me the $ sign. Could you please help me on this?

Regards,

Soumya

ok, I found out the solution , I set the custom property

cells[startRow + 2, 5].Style.Number = 12;

cells[startRow + 2, 5].Style.Custom = "$#,##0.00_);($#,##0.00)";

This works , i get the currency value displayed with a '$' as prefix .

Thanks

Regards,

Soumya

Yes, you are right.

Built-in number format will show currency according to your language. So in your case, a custom setting is needed.

In you code, you can remove this line of code and it will still work fine.

cells[startRow + 2, 5].Style.Number = 12;

Smile [:)] Thanks lots lock [lo]