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.

Code Format/Mark-up

Also called programming style or coding convention, a set of guide-lines how to style and format your text to make it more read- and maintain-able.

Formatting data

Determines how you should print a date, a double or any other data-type, for example by adding indentation, white-spaces or punctuation, or by presenting different aspects of data, e.g. showing only day and month of a date.

13625 questions
2618
votes
51 answers

How to format a number with commas as thousands separators?

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 doing it: function numberWithCommas(x) { x =…
Elias Zamaria
  • 96,623
  • 33
  • 114
  • 148
2446
votes
67 answers

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" How can I do this?
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
1872
votes
15 answers

How to prettyprint a JSON file?

How do I pretty-print a JSON file in Python?
Colleen
  • 23,899
  • 12
  • 45
  • 75
1212
votes
19 answers

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).
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
1168
votes
12 answers

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 string foo {0}. Is there a way to escape the brackets?
Pop Catalin
  • 61,751
  • 23
  • 87
  • 115
1113
votes
53 answers

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] = d[2] + ','; return [d[0], d[1], d[2],…
user3625547
  • 11,159
  • 3
  • 12
  • 6
947
votes
23 answers

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?
Brian Deacon
  • 21,384
  • 13
  • 39
  • 41
768
votes
24 answers

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 should be 520.00; How should the round_to_2dp()…
Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241
744
votes
21 answers

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 a different name as I can't find anything related…
HMR
  • 37,593
  • 24
  • 91
  • 160
726
votes
16 answers

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? (tried --format=oneline but that does not show the…
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
693
votes
9 answers

Pad a number with leading zeros in JavaScript

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 to do this would be to subtract the number minus 4…
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
676
votes
31 answers

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 method for each project. Is there a static method in Apache Commons for…
Igor Mukhin
  • 15,014
  • 18
  • 52
  • 61
610
votes
44 answers

std::string formatting like sprintf

I have to format std::string with sprintf and send it into file stream. How can I do this?
Max Frai
  • 61,946
  • 78
  • 197
  • 306
570
votes
10 answers

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?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
569
votes
28 answers

Commonly accepted best practices around code organization in JavaScript

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 handlers in one spot and write functions for all the…
hugoware
  • 35,731
  • 24
  • 60
  • 70
1
2 3
99 100