string formatting - Java getFloat troubles - decimals being truncated -


i'm querying postgres database storing floats. see in postgres inputs being stored decimal values, when query postgres java , put them textboxes via settext decimals being trimmed.

enter image description here

here's code:

statement stmnt = conn.createstatement();  resultset rs;  rs = stmnt.executequery("select * \"tblsamples\" "     + " \"fnname\" = '" + cmbfnname.getselecteditem().tostring() + "' limit 1;");  while ( rs.next() ) {         txtid.settext(rs.getstring("id"));         //attempt 1:          txtxoffset.settext(string.format("%f", rs.getfloat("fnxoffset")));         //attempt 2:          txtxoffset.settext(string.format("%0.000000000f", rs.getfloat("fnxoffset")));         //attempt 3:          txtxoffset.settext(string.format("%d",(long)rs.getdouble("fnxoffset")));                 } 

none of these things working. can't tell if it's because of "get" portion, "set" portion, or because string formatting isn't happening correctly.

to clear, want trim trailing zeroes, less important getting decimals in start with.

the correct format string . followed number of wanted digits followed f:

system.out.println(string.format("%.12f", 1.0)); 

just completeness, note user-entered values, database stores fixed point numbers in java called bigdecimal , not floating point numbers.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -