sprintf

Dealing with ugly SQL in Java

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly ? I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed. I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perhaps I can be convinced differently. Stored procedures are annoying to deploy/maintain, and parsing performance is not such a huge issue in my case -- flexibility takes precedence. HQL seems like a big

how to show certain number of decimal digits

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Matlab, how to control the number of decimal digits for displaying in command window? For example, >> x=0.4654 x = 0.4654 how to display the value of the variable x as 0.5, 0.47, 0.465 respectively in command window? Thanks! 回答1: I don't think there is built in rounding to arbitrary places, but you can achieve the rounded result by doing round(x*10^ number of places )/10^ number of places . This prints out with the trailing zeroes, if you want to get rid of those you have to do a specially formatted print like sprintf to the degrees so in

Why do variable lookups in the body of function A take values from the global environment but not function B that calls A?

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I defined a function: .get <- function( o, ...) { p <- match.call( expand.dots = 0)$... cat( sprintf( 'In .get, it is %s.\n', eval( tail( p, 1)[[ 1]]))) fn <- switch( typeof( o), list =, environment = `[[`, 'S4' = '@', `[`) if( length( p)) eval( as.call( c( fn, quote( o), p))) else o # Here when true, I compose a call based on p. } Then I tried it as follows: it <- 1 m <- matrix( seq( 9), 3) sapply( seq( 3), function( it) { cat( sprintf( 'In sapply, it is: %s.\n', it)) .get( m, , it) }) sapply( seq( 3), function( it) .get( m, , it)) The

php create navigation menu from multidimensional array dynamically

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I did research on this, and wasn't able to find an exact answer. Most of the questions/answers on here pertaining to this seem to be unfinished. If anyone knows of a finished solution similar to my question, please point me in that direction! Here is my array: Array ( ['home'] => Array ( [0] => sub-home1 [1] => sub-home2 ) ['about'] => Array ( [0] => sub-about ['about2'] => Array ( [0] => sub-sub-about ) ) ['staff'] => Array ( [0] => sub-staff1 [1] => sub-staff2 ) ['contact'] => contact ) And here is what I would like to turn it into: <ul>

sprintf invalid format '%d'

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This works: > sprintf ( '%d' , c ( 1 , 1.5 )) [ 1 ] "1" "1" and this doesn't: > sprintf ( '%d' , c ( 1.5 , 1 )) Error in sprintf ( "%d" , c ( 1.5 , 1 )) : invalid format '%d' ; use format % f , % e , % g or % a for numeric objects Why? 回答1: This is actually really interesting question. To start, %d stands for integer. The vector argument is recycled if possible but if it is c(1.5, 1) it will fail when sprintf() tries to replace %d with 1.5 (which is not integer). I thought it might be related to the fact that in R both integer and

how to convert a cell to string in matlab

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Suppose I have a cell v = 'v' [576.5818] [3.0286] [576.9270] 'v' [576.5953] [3.1180] [576.8716] 'f' [ 56] [ 58] [ 52] 'f' [ 56] [ 58] [ 52] and I want to convert this to a cell array using a format string for each element: ' %.5f' How can I do this? I tried the following approach, but I get an error: f1 = @(x) sprintf(' %.5f',x); cellfun(f1, num2cell(v),'UniformOutput', false) I am getting an error as ??? Error using ==> sprintf Function is not defined for 'cell' inputs. Error in ==> @(x)sprintf(' %.5f',x) Can any one help me thanks in

How to use index in the file name

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is probably trivial question. I am not a professional programmer, I am rather a mathematician who is doing some numerical experiment using C. I would like the output of my experiment to be written in different files for different values of a parameter. MWE should do something like this. Crate a file pointer indexed by i. Open a file named file[i]. Write i into that file and then close it. The code below obviously doesn't compile. Is such a construction even possible? #include<stdio.h> int i; int main() { for (i = 0; i < 10; i++){ FILE

sprintf for unsigned _int64

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am having following code. output of second %d in sprintf is always shown as zero. I think i am specifying wrong specifiers. Can any one help me in getting write string with right values. And this has to achieved in posix standard. Thanks for inputs void main() { unsigned _int64 dbFileSize = 99; unsigned _int64 fileSize = 100; char buf[128]; memset(buf, 0x00, 128); sprintf(buf, "\nOD DB File Size = %d bytes \t XML file size = %d bytes", fileSize, dbFileSize); printf("The string is %s ", buf); } Output: The string is OD DB File Size = 100

Gnuplot workflow involving loops of fits that get multiplotted

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to do the following in gnuplot: read my files, which are conveniently labeled "filenameN.txt", where N is the Nth file. Fit some polynom fN(x)to the data, using aN, bN,... and plot all of those in a single graphic (multiple plots) using multiplot However, I cannot get this to work using the loops available in gnuplot. What does work is for example creating one file, that does what I want for N, and then running an external loop that passes N=1...M. This results in M plots, but not in a single multiplot. For this to work I need to

YACC Rules not reduced

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is my code calc.y. I keep getting the error: yacc: 1 rule never reduced yacc: 3 reduce/reduce conflicts not really sure what this means Ive done some research in other places but I am now lost. Im guessing the rules being referred to is program and statement but even so... what does the reduce rule mean? %{ #include <stdio.h> FILE *outfile; int yyline = 1; int yycolumn = 1; %} %union{ int nw; struct{ int v; char s[1000]; }attr; } %token SEMInumber %token LPARENnumber %token <nw> ICONSTnumber %token BEGINnumber %token PROGRAMnumber