formatting

MVC DateTime binding with incorrect date format

Asp.net-MVC now allows for implicit binding of DateTime objects. I have an action along the lines of public ActionResult DoSomething(DateTime startDate) { ... } This successfully converts a string from an ajax call into a DateTime. However, we use the date format dd/MM/yyyy; MVC is converting to MM/dd/yyyy. For example, submitting a...

Java: Format number in millions

Is there a way to use DecimalFormat (or some other standard formatter) to format numbers like this: 1,000,000 => 1.00M 1,234,567 => 1.23M 1,234,567,890 => 1234.57M Basically dividing some number by 1 million, keeping 2 decimal places, and slapping an 'M' on the end. I've thought about creating a new subclass of N...

What does {0} mean when found in a string in c#?

Hi, In a dictionary like this: Dictionary<string, string> openWith = new Dictionary<string, string>(); openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); The output is: ...

Print leading zeros with C++ output operator (printf equivalent)?

How can I format my output in C++? In other words, what is the C++ equivalent to the use of printf like this: printf("%05d", zipCode); I know I could just use printf in C++, but I would prefer the output operator <<. Would you just use the following? std::cout << "ZIP code: " << sprintf("%05d", zipCode) << std::endl; ...

How to explain to a high school hacker that indenting and verbose variable names are good things?

He is good programmer (won some competitions) but he absolutely ignores formatting. He consider i, j, k beautiful... I hope he won't find out about existence of goto keyword. ...

C# Formatting - How to correctly format a name? I.e. forename or surname

I'm currently being visually assaulted by all of the names that are being displayed and entered on one of my systems. Basically, users have use of an on-screen keyboard and don't tend to write things in neatly! I.e. John Smith ends up getting entered as JOHN SMITH or john smith. I want a way to neatly enter names and display them. I've ...

Simple way to change 180 to 03:00

Hey! I am trying to change a number of seconds in to a proper time stamp format. Like I do this to change 180 to 03:00 private void writeTime(int tempo) { TimeSpan otempo = new TimeSpan(0, 0, tempo); string minutos = ((otempo.Minutes <= 9) ? "0" : "") + otempo.Minutes.ToString(); str...

Google Bookmark Export date format?

I been working on parsing out bookmarks from an export file generated by google bookmarks. This file contains the following date attributes: ADD_DATE="1231721701079000" ADD_DATE="1227217588219000" These are not standard unix style timestamps. Can someone point me in the right direction here? I'll be parsing them using c# if you are fe...

Pad left or right with string.format (not padleft or padright) with arbitrary string

Can I use String.Format() to pad a certain string with arbitrary characters? Console.WriteLine("->{0,18}<-", "hello"); Console.WriteLine("->{0,-18}<-", "hello"); returns -> hello<- ->hello <- I now want the spaces to be an arbitrary character. The reason I cannot do it with padLeft or padRight is because I w...

How to display 1 instead of 01 in ToString();

Hello, I am using the format ToString("0,0") to display a number like 5000 as 5,000 but if the number is 0 - 9, it displays 01, 02, 03, etc. Does anyone know the correct syntax so it does not display the leading 0? Thanks, XaiSoft ...

including spaces while using %w

The following code produces the output "xyz" a = %w{x y z} print a.to_s Is there an option that can be added to the block to allow spaces to be added? For example, I thought that by changing the code to this I might be able to space-separate the elements to produce an output of "x y z" a = %w{"x " "y " "z "} print a.to_s Instead...

Whitespace auto format - ReSharper and VS2008 fighting each other!

Consider the following line of code: things.Add(new Thing { ID = null, Name = "a thing" }); The whitespace formatting you see there is that which I get when I type the closing ;. Now, if I ask Visual Studio to reformat my code, or I type a closing } it gets reformatted: things.Add(new Thing{ID = null, Name = "a thing"}); I prefer ...

Can I pretty-print the DBIC_TRACE output in DBIx::Class?

Setting the DBIC_TRACE environment variable to true: BEGIN { $ENV{DBIC_TRACE} = 1 } generates very helpful output, especially showing the SQL query that is being executed, but the SQL query is all on one line. Is there a way to push it through some kinda "sql tidy" routine to format it better, perhaps breaking it up over multiple lin...

Can I pass parameters to String.Format without specifying numbers?

Is there a way to String.Format a message without having to specify {1}, {2}, etc? Is it possible to have some form of auto-increment? (Similar to plain old printf) ...

Format Repeating Decimal as a Fraction

I need to convert decimal values to their fractional equivalents, similar to this previous question. I'm using the code posted in one of the answers as a starting point since it mostly does what I need it to do. string ToMixedFraction(decimal x) { int whole = (int) x; int denominator = 64; int numerator = (int)( (x - whole) * denomina...

Why should I use a human readable file format?

Why should I use a human readable file format in preference to a binary one? Is there ever a situation when this isn't the case? EDIT: I did have this as an explanation when initially posting the question, but it's not so relevant now: When answering this question I wanted to refer the asker to a standard SO answer on why using a human...

How to convert between "#,##0" and "{0:n2}" style format string representations?

.NET supports two types of string formatting. I'm in a situation where existing configuration data has #,##0 style formatting. A new feature requires formatting to the same output, but the API needed for this feature only accepts formatting of type {0:n2}. Does anyone know of a means to convert between these two representations for nu...

How can I String.Format a TimeSpan object with a custom format in .NET?

What is the recommended way of formatting TimeSpan objects into a string with a custom format? ...

How to print a newline in an MS-DOS script?

I want to print the output of a program in MS-DOS so I wrote a .bat file that says: cls ruby foo.rb But the output - as it appears on my command prompt - looks like this: c:\workspace>ruby foo.rb foo output c:\workspace> I wanted to insert a newline into the output using MS-DOS because I don't want to pollute my Ruby code with anyt...

Best way to handle LARGE strings of text going into a database?

Hey all, I have built a number of solutions in the past in which people enter data via a webform, validation checks are applied, regex in some cases and everything gets stored in a database. This data is then used to drive output on other pages. I have a special case here where a user wants to copy/paste HUGE amounts of text (multiple...