Questions tagged [formatting]

The process of transforming text or data for presentation. A typical example would be the transformation of a decimal into a particular currency format with the correct number of decimal places.

Filter by
Sorted by
Tagged with
2343votes
56answers
1.7mviews

How to print a number with commas as thousands separators in JavaScript

I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? Here is how I am ...
user avatar
2253votes
69answers
2.4mviews

How to format numbers as currency strings

I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: "$ 2,500.00" What's the best way to do this?
1580votes
14answers
1.7mviews

How to prettyprint a JSON file?

I have a JSON file that is a mess that I want to prettyprint. What's the easiest way to do this in Python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how to ...
user avatar
  • 20.7k
1147votes
18answers
731kviews

How can I pad an integer with zeros on the left?

How do you left pad an int with zeros when converting to a String in java? I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
user avatar
  • 52.6k
1107votes
11answers
329kviews

How to escape braces (curly brackets) in a format string in .NET

How can brackets be escaped in using string.Format? For example: String val = "1,2,3" String.Format(" foo {{0}}", val); This example doesn't throw an exception, but it outputs the ...
user avatar
  • 59.5k
925votes
21answers
538kviews

How do I change Eclipse to use spaces instead of tabs?

By default Eclipse indents with a hard tab character. How do I change it to spaces?
user avatar
  • 20.2k
811votes
46answers
1.9mviews

Format JavaScript date as yyyy-mm-dd

I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript? function taskDate(dateMilli) { var d = (new Date(dateMilli) + '').split(' '); d[2] = ...
user avatar
  • 8,139
686votes
25answers
1.5mviews

Show a number to two decimal places

What's the correct way to round a PHP string to two decimal places? $number = "520"; // It's a string from a database $formatted_number = round_to_2dp($number); echo $formatted_number; The output ...
user avatar
649votes
30answers
309kviews

How can I convert byte size into a human-readable format in Java?

How can I convert byte size into a human-readable format in Java? Like 1024 should become "1 Kb" and 1024*1024 should become "1 Mb". I am kind of sick of writing this utility ...
user avatar
612votes
16answers
243kviews

The shortest possible output from git log containing author and date

How can I show a git log output with (at least) this information: * author * commit date * change I want it compressed to one line per log entry. What's the shortest possible format for that? (...
user avatar
610votes
18answers
564kviews

How to change indentation in Visual Studio Code?

For every typescript file visual studio code uses an auto indentation of 8 spaces. This is a bit too much for my taste but I can't find where to change it. Maybe it's available as a setting but under ...
user avatar
  • 33.7k
593votes
9answers
636kviews

Pad a number with leading zeros in JavaScript [duplicate]

In JavaScript, I need to have padding. For example, if I have the number 9, it will be "0009". If I have a number of say 10, it will be "0010". Notice how it will always contain four digits. One way ...
user avatar
  • 40.6k
568votes
10answers
222kviews

Eclipse: Set maximum line length for auto formatting?

I am working with Java. If I hit Ctrl+Shift+F in Eclipse Helios, it will auto format my code. At a certain point, it wraps lines. I would like to increase the maximum line length. How can I do this?
user avatar
568votes
28answers
51kviews

Commonly accepted best practices around code organization in JavaScript [closed]

As JavaScript frameworks like jQuery make client side web applications richer and more functional, I've started to notice one problem... How in the world do you keep this organized? Put all your ...
user avatar
  • 34.3k
562votes
41answers
1.1mviews

std::string formatting like sprintf

I have to format std::string with sprintf and send it into file stream. How can I do this?
user avatar
  • 56.9k

15 30 50 per page
1
2 3 4 5
852