format

can there be less number of fomat specifier than the number of variables in a printf statement

痞子三分冷 提交于 2019-12-14 02:48:00
问题 I have coded the following program in a borland c compiler.My doubt is why c compiler doesnot throw any error neither in compile time or run time.The program executes fine and the output is 2 4. #include<stdio.h> #include<conio.h> int main(){ int a=2,b=4,c=6; printf("%d%d",a,b,c); getch(); return 0; } Even though there are less no of format specifiers than the number of arguments there is no error thrown.What is happening here. 回答1: can there be less number of fomat specifier than the number

JExcelApi: multiple formats in one cell?

坚强是说给别人听的谎言 提交于 2019-12-14 02:16:30
问题 In Excel, I can have multiple text styles in a single cell. Is there a way to create a file like this using JExcelApi? I'm not seeing anything so far: setCellFormat is a method on WritableCell, and there doesn't seem to be any way to set a format for anything within a single cell. Am I just missing it (quite possible!), or is this not implemented? As a bonus: how hard would this be to implement? Is there any other Excel-export library which does implement this, from which I could borrow the

DateTime formatting and timezone

眉间皱痕 提交于 2019-12-14 01:13:44
问题 When trying to parse a Date with DateTime::createFromFormat PHP will not recognize the timezone. Example: $t = new \DateTime(); echo $t->format('Y-m-dTH:i:s'); will output 2012-01-24MSK16:53:52 Now when I try to parse that string from the same format var_dump(\DateTime::createFromFormat('Y-m-dTH:i:s', '2012-01-24MSK16:53:52')); I get bool(false) When I do not put the Timezone into the string, it works $t = new \DateTime(); echo $t->format('Y-m-dH:i:s'); will give 2012-01-2417:17:24 and

How do I create a DateFormat with an optional time argument?

回眸只為那壹抹淺笑 提交于 2019-12-14 00:52:24
问题 I wish to construct a date format that will optionally have a time argument. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd [hh:mm]"); Is it also possible to construct a date format object that is capable of parsing different formats? Such as try the current locale but then fall back to ISO-8601 or should I just write multiple date formats if one fails? UPDATE : Looking back at this question I can see I didn't specify that the reason for multiple date formats was for parsing strings

Smart way to format tables on stdout in C

China☆狼群 提交于 2019-12-14 00:25:47
问题 I am trying to write table to stdout with numerical data. I would like to format so that numbers are aligned like: 1234 23 312 2314 12 123 I know that max length of the number is 6 chars, is there a smart way to know how many spaces needs to be output before number so it looks exactly like this? 回答1: printf may be the quickest solution: #include <cstdio> int a[] = { 22, 52352, 532 }; for (unsigned int i = 0; i != 3; ++i) { std::printf("%6i %6i\n", a[i], a[i]); } Prints: 22 22 52352 52352 532

Filter days of week and just show working days in php

不问归期 提交于 2019-12-13 23:46:31
问题 I am trying to create a drop down with just the working days of the week on. Monday - Friday. Here's my code: <?php if ($_SESSION['month'] == $current_month) { $current_day = date("j") + 1;} else {$current_day = 1;} ?> <form action="" method="post"> <select name="day" onchange="this.form.submit()"> <option value="">-- Day --</option> <?php for ($i = $current_day; $i < 31; $i++) { ?> <option value="<?php echo $i; ?>" <?php echo $i == $_SESSION['day'] ? "selected='selected'":""; ?> > <?php $tmp

SimpleDateFormat and not allowing it to go above 12 hours [closed]

孤街醉人 提交于 2019-12-13 23:04:01
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . So I have this method that I wanted to expand on to have the user input a valid 12 hour time. And I have it to this which works okay. But I want it so that if the hour is over 12 hours or the minutes is over 59 then it will prompt to do it again. But right now it will just convert

JSON.Net Seralize values don't have quotation marks

人走茶凉 提交于 2019-12-13 22:55:07
问题 The following code: var json = JsonConvert.SerializeObject(fooObject, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, }); Seralizes a json (string) object of: { "fooA":0, "fooB":0, "fooC":false, "fooD":false, "fooE":0, "fooF":0, } The values are not in quotation marks, such as "fooA":"0". This is the behavior that I want. Is there a way to enforce this behavior? 回答1: In JSON format, numbers and booleans do not have quotes around them, while strings do (see JSON.org)

How to format the printing of doubles

余生颓废 提交于 2019-12-13 21:03:54
问题 Im making a division table from 1-10 an the results range from integers to x.x to x.xx i used decimalformat to keep the the numbers to 2 decimal places but that throws off the format of the table. How would i print the numbers so that they would all be x.xx for example 1 -> 1.00 0.5 -> 0.50 0.333... -> 0.33 DecimalFormat df = new DecimalFormat("#.##"); System.out.println(" 1 2 3 4 5 6 7 8 9 10"); for(double i=1;i<=10;i++){ System.out.print(df.format(i)+" "); if (i<10) System.out.print(" ");

C++: Printing with conditional format depending on the base of an int value

两盒软妹~` 提交于 2019-12-13 20:13:26
问题 In c++, Is there any format specifier to print an unsigned in different base, depending on its value? A format specifier expressing something like this: using namespace std; if(x > 0xF000) cout << hex << "0x" << x; else cout << dec << x ; Because I will have to do this a lot of times in my current project, I would like to know if c++ provides such a format specifier. 回答1: There is no such functionality built-in to C++. You can use a simple wrapper to accomplish this, though: struct large_hex