format

Java double to string with specific precision

↘锁芯ラ 提交于 2019-12-05 01:01:01
I would like to convert double into String . I want it to have as few digits as possible and maximally 6. So I found String.format("%.6f", d) which converts my 100.0 into 100.000000 . Max precision works correctly, but I would like it to be converted to 100 (minimum precision). Have you got any idea what method is working like that? Thomas Use DecimalFormat : new DecimalFormat("#.0#####").format(d) . This will produce numbers with 1 to 6 decimal digits. Since DecimalFormat will use the symbols of the default locale, you might want to provide which symbols to use: //Format using english symbols

Format double - thousands separator with decimal but no trailing zeros

馋奶兔 提交于 2019-12-05 00:45:39
问题 I am looking for a format to use with string.Format that would print the following double d = 123456.123456D; double d2 = 123456D; like 123,456.123456 123,456 {0:N6} results in 123,456.123456 123,456.000000 {0:0.######} results in 123456.123456 123456 {0:#.0} results in 123,456 123,456 I cannot workout a format that will get me to what I need. Will I need to define my own format provider ? 回答1: You're close. Use this format: {0:#,0.######} 来源: https://stackoverflow.com/questions/20146370

how to customize “TimeStamp” format of Boost.Log

元气小坏坏 提交于 2019-12-05 00:04:12
I want to get year-month-day hour:minute:second.fraction(2 digits), if I use "%Y-%m-%d %H:%M:%S.%f", I got almost what I want exception for the fraction( last part ) of seconds, it's showing 6 digits on my Windows XP, I don't know how to get 2 digits only, any idea? Boaz Yaniv Boost.DateTime (upon which Boost.Log relies) doesn't seem to support specialized fractional seconds formatting, so the only way to do that would be to write your own custom attribute formatter, or (the easier, but less nice way) to slightly modify your formatting code. Instead of something like this: backend->set

Why does DateTime::createFromFormat() fails and returns a boolean in my second example?

吃可爱长大的小学妹 提交于 2019-12-04 23:35:16
When I run this the first one is correctly created into a date. The second one fails, returning a boolean and so I cannot format. Is the time out of range? //works correctly $startDate = "2015-05-06 10:49:20.637133"; $start = DateTime::createFromFormat('Y-m-d h:m:s.u',$startDate); echo $start->format('m/d/y'); //doesn't work correctly $startDate = "2015-05-12 15:49:06.821289"; $start = DateTime::createFromFormat('Y-m-d h:m:s.u',$startDate); echo $start->format('m/d/y'); Code to reproduce the error Change the h to a big H , since the small one is 12-hours format and the big one is 24-hours

How can I use a dynamic format string with the format! macro?

半腔热情 提交于 2019-12-04 22:53:43
I just started learning Rust, and I'm making some small tools to help me understand the language. I have a problem formatting a String using the format! macro. As format! takes a literal, I am not able pass my string to it. I want to do this to dynamically add strings into the current string for use in a view engine. I'm open for suggestions if there might be a better way to do it. let test = String::from("Test: {}"); let test2 = String::from("Not working!"); println!(test, test2); What I actually want to achieve is the below example, where main.html contains {content} . use std::io::prelude::

Robots.txt - What is the proper format for a Crawl Delay for multiple user agents?

回眸只為那壹抹淺笑 提交于 2019-12-04 22:42:16
Below is a sample robots.txt file to Allow multiple user agents with multiple crawl delays for each user agent. The Crawl-delay values are for illustration purposes and will be different in a real robots.txt file. I have searched all over the web for proper answers but could not find one. There are too many mixed suggestions and I do not know which is the correct / proper method. Questions: (1) Can each user agent have it's own crawl-delay? (I assume yes) (2) Where do you put the crawl-delay line for each user agent, before or after the Allow / Dissallow line? (3) Does there have to be a blank

How to draw a checkered flag to the Python screen?

可紊 提交于 2019-12-04 22:10:55
QUESTION: Implement the following pseudocode to draw a checkered flag to the screen. 1. Ask the user for the size of the checkered flag (n). 2. Draw an n x n grid to the screen. 3. For i = 0,2,4,...,62: 4. row = i // n 5. offset = row % 2 6. col = (i % n) + offset Please copy and paste the link see the ouput: http://www.awesomescreenshot.com/image/45977/12eaef67de44c2b291ecd47fe8d10135 I implemented the pseudocode, but I need some help. I am keep getting this error: row, col = findGrid(x) TypeError: 'int' object is not iterable My program: from turtle import* def size(): size = eval(input(

SAS change date format

我与影子孤独终老i 提交于 2019-12-04 20:41:35
I want to define a date format that takes the following format : 12JAN2010 I tried using this code : /* partie B question 2*/ data projet.Ophtalmo_new; set projet.Ophtalmo_new (RENAME=(date_diagnostic=date_dia)) (RENAME= (date_examen=date_exa)); date_diagnostic = input (date_dia, DDMMYY10.); date_examen = input (date_exa, DDMMYY10.); format date_diagnostic date_examen date9.; run; But it sends me the following syntax error : ERROR 22-322: Syntax error, expecting one of the following: un nom, une chaîne entre guillemets, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_,

How can I change DecimalFormat behavior based on input length?

喜欢而已 提交于 2019-12-04 20:31:42
问题 I am using the following DecimalFormat pattern: // Use ThreadLocal to ensure thread safety. private static final ThreadLocal <NumberFormat> numberFormat = new ThreadLocal <NumberFormat>() { @Override protected NumberFormat initialValue() { return new DecimalFormat("#,##0.00"); } }; This performs the following conversions: 1 -> 1.00 1.1 -> 1.10 1.12 -> 1.12 I now have an additional requirement. 1.123 -> 1.123 1.1234 -> 1.123 That means that when there are fewer than two decimal places, I will

Read large txt file in c++

柔情痞子 提交于 2019-12-04 18:12:53
I'd like to read a file of about 5MB in memory ... the file has this format (it is a text file) ID 3: 0 itemId.1 0 itemId.2 0 itemId.5 1 itemId.7 ........................ 20 itemId.500 ID 50: 0 itemId.31 0 itemId.2 0 itemId.4 2 itemId.70 ........................ 20 itemId.2120 ..... how can I do this efficiently in c++? Martin York Reading a file line by line: ifstream fin ("file.txt"); string myStr; while(getline(fin, myStr)) // Always put the read in the while condition. { // Then you only enter the loop if there is data to //use myStr data // processes. Otherwise you need to read and then }