How to use Decimal format specifier and fixed point specifier together on a double variable

Hi,

I have 2 questions.

  1. In the screenshot below, acnum is an object[ .]array while val1 is a double variable. I’m trying to convert acnum(0) item into “00000.00” format and thrown with an error.

  2. How to get the features of
    " acnum(0).tostring(“D5”) " --//I understand this works only for INT
    As well as
    acnum(0).tostring(“F2”,CultureInfo.InvariantCulture) together?

What is the fundamental piece of understanding that I am missing here. Any help appreciated.

PS: The screenshot attached is just a test file. Actually I’ll be passing the array argument from another xaml.

Hi @SudhakarAs92
Buddy you were almost right, but need small correction
At last the writeline activity must be mentioned like this
String.Format(“{0:00}”, acnum(0))

And the reason why this didn work is, it should be in This format
String.Format(“{0:F2}”,acnum(0))

For more info on how to use it
https://social.msdn.microsoft.com/Forums/en-US/685780a0-e997-47e1-8979-dca94b5708d0/setting-decimal-limited-to-2-digits?forum=csharpgeneral

Try with this and let know buddy
Cheers @SudhakarAs92

Thanks for the response!

String.Format(“{0:F2}”,acnum(0)) solved my query partially though…

Meanwhile, the below line worked for me satisfying both the formats that i needed.

convert.ToDouble(acnum(0)).ToString(“F2”,CultureInfo.InvariantCulture).PadLeft(5,Cchar(“0”))

If there are any other efficient way to achieve this, do share. Thankz!

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.