How to disable scientific notation?
You can effectively remove scientific notation in printing with this code: options(scipen=999)
You can effectively remove scientific notation in printing with this code: options(scipen=999)
Use the standard Java DateFormat class. For example to display the current date and time do the following: Date date = new Date(location.getTime()); DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); mTimeText.setText(“Time: ” + dateFormat.format(date)); You can initialise a Date object with your own values, however you should be aware that the constructors have been deprecated and you should … Read more
ES2017 Update You can use the built-in String.prototype.padStart() n = 9; String(n).padStart(4, ‘0’); // ‘0009’ n = 10; String(n).padStart(4, ‘0’); // ‘0010’ Not a lot of “slick” going on so far: function pad(n, width, z) { z = z || ‘0’; n = n + ”; return n.length >= width ? n : new Array(width … Read more
The json module already implements some basic pretty printing in the dump and dumps functions, with the indent parameter that specifies how many spaces to indent by: >>> import json >>> >>> your_json = ‘[“foo”, {“bar”:[“baz”, null, 1.0, 2]}]’ >>> parsed = json.loads(your_json) >>> print(json.dumps(parsed, indent=4, sort_keys=True)) [ “foo”, { “bar”: [ “baz”, null, 1.0, … Read more
Format JavaScript date as yyyy-mm-dd
NSDate objects don’t have time zones. They represent an absolute moment in time. However, when you ask one for its description (by printing it with NSLog(), e.g.), it has to pick a time zone. The most reasonable “default” choice is GMT. If you’re not in GMT yourself, the date will seem to be incorrect, by … Read more
You can use number_format(): return number_format((float)$number, 2, ‘.’, ”); Example: $foo = “105”; echo number_format((float)$foo, 2, ‘.’, ”); // Outputs -> 105.00 This function returns a string.
Use strtotime() and date(): $originalDate = “2010-03-21”; $newDate = date(“d-m-Y”, strtotime($originalDate)); (See the strtotime and date documentation on the PHP site.) Note that this was a quick solution to the original question. For more extensive conversions, you should really be using the DateTime class to parse and format 🙂
Use java.lang.String.format(String,Object…) like this: String.format(“%05d”, yournumber); for zero-padding with a length of 5. For hexadecimal output replace the d with an x as in “%05x”. The full formatting options are documented as part of java.util.Formatter.
The short version: use formatC or sprintf. The longer version: There are several functions available for formatting numbers, including adding leading zeroes. Which one is best depends upon what other formatting you want to do. The example from the question is quite easy since all the values have the same number of digits to begin … Read more