How to format strings in Java
Primitive question, but how do I format strings like this: “Step {1} of {2}” by substituting variables using Java? In C# it’s easy. 10 Answers 10
Primitive question, but how do I format strings like this: “Step {1} of {2}” by substituting variables using Java? In C# it’s easy. 10 Answers 10
How can I format a datetime object as a string with milliseconds? 15 Answers 15
Kotlin has an excellent feature called string templates. val i = 10 val s = “i = $i” // evaluates to “i = 10” But is it possible to have any formatting in the templates? For example, I would like to format Double in string templates in kotlin, at least to set a number of … Read more
I have a number that I need to convert to a string. First I used this: Key = i.ToString(); But I realize it’s being sorted in a strange order and so I need to pad it with zeros. How could I do this? 11 Answers 11
I want to display: 49 as 49.00 and: 54.9 as 54.90 Regardless of the length of the decimal or whether there are are any decimal places, I would like to display a Decimal with 2 decimal places, and I’d like to do it in an efficient way. The purpose is to display money values. eg, … Read more
I have got a price field to display which sometimes can be either 100 or 100.99 or 100.9, What I want is to display the price in 2 decimal places only if the decimals are entered for that price , for instance if its 100 so it should only show 100 not 100.00 and if … Read more
This question already has answers here: Display number with leading zeros (17 answers) Closed 5 years ago. I need to add leading zeros to integer to make a string with defined quantity of digits ($cnt). What the best way to translate this simple function from PHP to Python: function add_nulls($int, $cnt=2) { $int = intval($int); … Read more
Is there a simple way to format a string in Go without printing the string? I can do: bar := “bar” fmt.Printf(“foo: %s”, bar) But I want the formatted string returned rather than printed so I can manipulate it further. I could also do something like: s := “foo: ” + bar But this becomes … Read more
Is it possible to have placeholders in string values in string.xml that can be assigned values at run time? Example: some string PLACEHOLDER1 some more string 14 s 14 Formatting and Styling Yes, see the following from String Resources: Formatting and Styling If you need to format your strings using String.format(String, Object…), then you can … Read more
I want to fill out a string with spaces. I know that the following works for zero’s: >>> print “‘%06d'”%4 ‘000004’ But what should I do when I want this?: ‘hi ‘ of course I can measure string length and do str+” “*leftover, but I’d like the shortest way. 14 s 14 You can do … Read more