formatting

Formatting DataBinder.Eval data

How can I format data coming from a DataBinder.Eval statement in an ASPX page? For example, I want to display the published date of the news items in a particular format in the homepage. I'm using the ASP.NET 2.0 Repeater control to show the list of news items. The code for this goes like this: <asp:Repeater ID="Repeater1" runat="serv...

Java: Print a 2D String array as a right-justified table

What is the best way to print the cells of a String[][] array as a right-justified table? For example, the input { { "x", "xxx" }, { "yyy", "y" }, { "zz", "zz" } } should yield the output x xxx yyy y zz zz This seems like something that one should be able to accomplish using java.util.Formatter, but it doesn't seem to allow n...

Line width formatting standard

Do you follow a standard for wrapping long lines in source code? What line length do you find most comfortable to read? Sometimes I find people who program on wide-screen monitors and like to use its full width for displaying source code. I prefer shorter lines, around 80-100 characters, but I have a hard time trying to convince colleag...

stop Ms Excel auto-formatting numeric strings as numbers

I am exporting a report from MS Access(2003) to Excel (97-2003) output. One of the columns has a character string that is numeric for some rows e.g. "05-0880". When I open the output file in MS Excel the corresponding cell is set to the number -372424. I assume this is caused by Excel being "clever" and deciding that "05-0808" repres...

Any command line format tool available for java file?

We are working on a legacy system(7 years old), with lots of java/jsp files that have never been formatted before, not reader at all. Because we have many old versions, we are afraid that we won't be able to effectively diff unformatted and formatted files anymore if we format them. Question is: are there any command line format tools a...

Looking for a configurable pretty printer for C# code.

I work on a team with about 10 developers. Some of the developers have very exacting formatting needs. I would like to find a pretty printer that I could configure to these specifications and then add to the build processes. In this way no matter how badly other people mess up the format when it is pulled down from source control it will...

StAX XML formatting in Java

Is it possible using StAX (specifically woodstox) to format the output xml with newlines and tabs, i.e. in the form: <element1> <element2> someData </element2> </element1> instead of: <element1><element2>someData</element2></element1> If this is not possible in woodstox, is there any other lightweight libs that can do this? ...

Left-pad printf with spaces

How can I pad a string with spaces on the left when using printf? For example, I want to print "Hello" with 40 spaces preceding it. Also, the string I want to print consists of multiple lines. Do I need to print each line separately? EDIT: Just to be clear, I want exactly 40 spaces printed before every line. ...

Decimal DateTime formatter in Java or Joda

I'm writing a file that requires dates to be in decimal format: 2007-04-24T13:18:09 becomes 39196.554270833331000 Does anyone have a time formatter that will do this (Decimal time is what VB/Office, etc. use)? Basic code goes like follows: final DateTime date = new DateTime(2007, 04, 24, 13, 18, 9, 0, DateTimeZone.UTC); double ...

Formatting strings in C# consistently throughout a large web application

I'm looking for a consistent way to structure my use of formatting strings throughout a large web application, and I'm looking for recommendations or best practices on which way to go. Up until now I've had a static class that does some common formatting e.g. Formatting.FormatCurrency Formatting.FormatBookingReference I'm not convinc...

How do I format a number to a dollar amount in PHP

How do you convert a number to a string showing dollars and cents? eg: 123.45 => '$123.45' 123.456 => '$123.46' 123 => '$123.00' .13 => '$0.13' .1 => '$0.10' 0 => '$0.00' ...

Format a number with commas, but keep decimals

I'd like to group the digits in a double by thousands, but also output however number of decimals are actually in the number. I cannot figure out the format string. 1000 => 1,000 100000 => 100,000 123.456 => 123.456 100000.21 => 100,000.21 100200.123456 => 100,200.123456 Disclaimers (it's not as straightforward as you think): ...

Do you generate nicely formatted HTML?

When using some server-side technology which is outputting HTML, do you try to format the output nicely? For example, adding line breaks and indentation? What are the pros and cons of either style? ...

What ways are there to reformat/revalidate a tree of controls in Flex other than ValidateNow()

I am having problems with text with multiple lines not reformatting properly when I call loadStyleDeclarations. However if I load the same stylesheet TWICE then it correctly refreshes and reformats the text. So what I want to do is refresh my control to get it to reformat the text. I've tried ValidateNow() and ValidateDisplayList() but ...

How would you format/indent this piece of code?

How would you format/indent this piece of code? int ID = Blahs.Add( new Blah( -1, -2, -3) ); or int ID = Blahs.Add( new Blah( 1,2,3,55 ) ); Edit: My class has lots of parameters actually, so that might effect your response. ...

Currency formatting in Python

Hey, I am looking to format a number like 188518982.18 to £188,518,982.18 using Python. How can I do this? Cheers ...

How do I use an email template txt file and retain formatting?

I'm using a preformatted text file as a template for emails. The file has line breaks where I want them. I'd like to use this template to send a plain text email, but when I do I'm losing all formatting. Line breaks are stripped. How do I parse this file and retain line breaks? I don't want to use a <pre> tag because I want to send plai...

How to convert an interval like "1 day 01:30:00" into "25:30:00"?

I need to add some intervals and use the result in Excel. Since sum(time.endtime-time.starttime) returns the interval as "1 day 01:30:00" and this format breaks my Excel sheet, I thought it'd be nice to have the output like "25:30:00" but found no way to do it in the PostgreSQL documentation. Can anyone here help me out? ...

What markup language for richly formated content?

When you are developing a web-based application and you want to allow richly formatted text from the user you have to make a choice about how to allow that input. Many different markup languages have been created because it is arguably more difficult to sanitize HTML. What are the advantages and disadvantages of the various different m...

Custom numeric format string to always display the sign

Is there any way I can specify a standard or custom numeric format string to always output the sign, be it +ve or -ve (although what it shoudl do for zero, I'm not sure!) ...