C# --- A number formatting question. How to solve remaonder zeros from being dropped. And output tricks.
Posted on 2005-03-11
Please excuse the seemingly "Newbie nature of my questions. I am very new to programming, so if you can show things by example code I would greatly appreciate it. So...
I am passing a "variant array by reference into this function that I didn't write and can't edit. Anyway when it returns an object refererence to a float the values contained in these array elements show the following...
FYI "=" doesn't mean in my example that I'm passing the value into the array element but rather showing you what the value of that element is in the debugger.
Array = 1.2567
Array = 1.25
Array = 1.254
Anyway my problem is that the number of decimal places is not the same! What I want is an array that contains the following using the example above..
Array = 1.2567
Array = 1.2500
Array = 1.2540
This must obviously be based on which ever element in the array has the largest number of decimal places and then making the rest adhere to that. This is because the array that come back to us from the function will always be giving an array with different MAX decimal places. Can't tell how many before hand etc.
My questions are as follows...
1) I know the values are the same but if I wanted to loop thru these returned arrays and print out the values to a CSV delimited text file, I would like the number of decimal places equal. Can someone show me with a code example how to do this? Remember that every call to this function/method will result in any number of MAX number of decimal places.
2) Also is there any way to have the float array identify the largest number of decimals it contains and display the rest to match this with remainder zero's? Should I copy this float array to a string array first or is this an uneeded step. The goal is to eventually print these values to a CSV text file.
3) If I had separate arrays which represent "columns" of data For example, ArrayCustNum, ArrayCustName, ArrayCustCountry And I wished to print them out to a comma separated/Delimited text file. Is it best to just loop thru the arrays and print to the text file line by line (do it manually) or is there a trick to quickly do this....I don't know "PrintTo/Convert to CSV file with these arrays in this order..." or something requiring 2 or 3 lines of code.
4) Lastly I want a method to select a path based on the first charater of a file name. Is there a trick (once a root directory is decided upon) to have a text file thrown/created/saved into alphabetised sub-folders? For example the sub folders might look like this...
"$%" folder that gets any file named with name that begins with a symbol (non letter or number char) charater
"1-9" folder that gets any file named with a name that begins with a number character
I wish to thank you for your generous help in advance. I hope this question isn't too long or too involved.