I want the following code to show only rounded numbers by two decimals . . .    public class Main {      public static void main(String[] args) {          double gross = 4322.12d;         double tax = 397.04d;          double net = gross - tax;         double fee = gross * 0.30d;         double vat = fee * 0.20d;         double takeHome = net - (fee + vat);          System.out.println("Gross Refund £" + gross);         System.out.println("Tax Deducted £" + tax);         System.out.println("Net Refund £" + net);         System.out.println("Our Fee £" + (fee + vat));         System.out.println("Funds remaining after deductions £" + takeHome);      }  }
What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.  I also would like only significant digits to be displayed - i.e. there should not be any trailing zeroes.  I know one method of doing this is to use the String.format method:  String.format("%.5g%n", 0.912385);   returns:  0.91239   which is great, however it always displays numbers with 5 decimal places even if they are not significant:   String.format("%.5g%n", 0.912300);   returns:  0.91230   Another method is to use the DecimalFormatter:  DecimalFormat df = new DecimalFormat("#.#####"); df.format(0.912385);   returns:  0.91238   However as you can see this uses half-even rounding. That is it will round down if the previous digit is even. What I'd like is this:  0.912385 -&gt; 0.91239 0.912300 -&gt; 0.9123   What is the best way to achieve this in Java?
Should Indicate which Positions I've Already Applied For What does a "CALLBACK" declaration in C do? I was looking through some code from the  library and came across a function declared like this:  LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)   Now, I'm a Delphi coder.  No hablo C muy bien, senor.  But I remember enough syntax from my college courses to read it like this:  Function name is WndProc.  Argument list is pretty self-explanatory.  Function return type is LRESULT.  But what in the world is that "CALLBACK" doing there?  In Delphi, any function can be used as a callback; you just need to pass the right type of function pointer.  Is there any particular reason why C doesn't work that way?  Or does it mean something different? Long-distance Mind Trick Which is the correct gerund clause? 'People's killing animals', or 'People killing animals ... '? By taking courses, I have learned topic A. Through self-studying and discussion with others, I have explored topic B.    I also study topic A outside the classroom. What I want to emphasis is that topic B is not in my curriculum, but I study it on my own. Extracurricular activities can include both activities contributed to academic study although outside the normal curriculum, but also activities not contributed to academic study such as sports, volunteer work, etc. I want to emphasis the former activities. Do you say "outside classes", when mentioning study by yourself, i.e.      Outside classes, I have explored B.      If it were you, how would you rewrite the first quote for the same       meaning?    Thanks! Am I technically allowed to look up cards during a Magic tournament match? Am I allowed to look up a card during a game, if it's being played with serious Rules Enforcement? Either to read the full card from the Gatherer, or to try to find the exact card I'm vaguely thinking of.  Two possible scenarios:   An opponent has revealed a card previously, and I want to remember the exact details. (Something like the exact wording of a sorcery, mana cost, keywords on a creature, subtypes, etc. etc.) I have a "name a card and remove it from the opponent's deck" type card, and I want to, say, ask google for "Blue Gearhulk" to remember that it's that that one is called "Torrential Gearhulk".   Obviously, in casual or semi-casual games neither of these are a problem. Any reasonable opponent will just re-reveal the known card (assuming it IS still guaranteed to be known) or will accept "I name the Blue Gearhulk".  Also obviously, it seems unlikely that I (or anyone else) would get to the stage of playing at the REL without knowing the cards too thoroughly for this to be relevant.  But in principle... is it permitted? Or not? (and if not, is there a good reason, or just "we decided 'No'"?) Rendering an animation the way 3D view looks Is there some way to render exactly whats in the camera view in the 3D view? By that I mean just like a screenshot really, all paths, lamps, and cameras, just like things look in the camera view. The reason I can't just take a screenshot is that I need an animation and it would be too cumbersome to take 1000+ screenshots! So I took an introductory abstract algebra course a few semesters ago, and we were shown that groups and rings can both be made into products, i.e. if I have some group $G$ (resp. ring $R$) and some indexing set $I$, then I can make a group $G^{I}$ (resp. ring $R^{I}$) with the appropriate cardinality. However, it was also demonstrated that for fields, you cannot keep the multiplicative inverse under a product structure, i.e. if I have fields $F_{1}, F_{2}$, then $F_{1} \times F_{2}$ will still be a ring, but you will not (not just "not in general", but won't) have multiplicative inverses for all non-zero (i.e. not $(0, 0)$) elements, as you could pick $(0, x)$, where $x \neq 0$. According to Wikipedia, an ultraproduct will preserve field structure, but I'm not sure what the cardinality of $\prod_{i \in I} F_{i} / \mathscr{U}$ would be in general.  I saw  that said you could make a field of arbitrarily large cardinality by extending a given field through throwing in a whole bunch of "transcendental" elements. The example given was that if I had $\mathbb{Q}$, I could start by dumping in the complexes, but then I suppose after that I'd just start throwing in dogs and cats or something; I'm really not sure what that responder meant, and ceteris paribus, my dogs tend to stay inside, so I'd rather keep them out of my fields, particularly the large ones the thread was interested in.  Moreover, the thread mentioned earlier seemed more concerned with just making the fields big. My question is a bit more nuanced: Given any cardinality $\kappa &gt; 1$, can I generally construct a field $F$ of a cardinality $\kappa$? Moreover, how vague do I have to be about it (i.e. do I have to use some really choicy methods, or can I make it a bit more straightforward)?  Thanks.  EDIT: Sorry. I am aware that for finite fields, you are limited to powers of primes. I meant for infinite cardinals. QGtkStyle was unable to detect the current GTK+ theme When I start any Qt app, I get this message in the terminal, and the Qt app doesn't use the same theme as my Gtk apps:  QGtkStyle was unable to detect the current GTK+ theme.   How do I make QGtkStyle detect my current GTK+ theme?  It seems that LXDE is using a settings daemon, and there is no gtkrc-2.0 file in my home folder. Prove that if $P$ is a $p$-Sylow subgroup of $G$ and $N \triangleleft\&gt; G$ then:    $ PN/N $ is a $p$-Sylow subgroup of $G/N$ $P \cap N $ is a $p$-Sylow subgroup of $N$ Intuitive explanation for density of transformed variable? Suppose $X$ is a random variable with pdf $f_X(x)$. Then the random variable $Y=X^2$ has the pdf   $$f_Y(y)=\begin{cases}\frac{1}{2\sqrt{y}}\left(f_X(\sqrt{y})+f_X(-\sqrt{y})\right) &amp; y \ge 0 \\ 0 &amp; y \lt 0\end{cases}$$   I understand the calculus behind this. But I'm trying to think of a way to explain it to someone who doesn't know calculus. In particular, I'm trying to explain why the factor $\frac{1}{\sqrt{y}}$ appears out front. I'll take a stab at it:  Suppose $X$ has a Gaussian distribution. Almost all the weight of its pdf is between the values, say, $-3$ and $3.$ But that maps to 0 to 9 for $Y$. So, the heavy weight in the pdf for $X$ has been extended across a wider range of values in the transformation to $Y$. Thus, for $f_Y(y)$ to be a true pdf the extra heavy weight must be downweighted by the multiplicative factor $\frac{1}{\sqrt{y}}$  How does that sound?  If anyone can provide a better explanation of their own or link to one in a document or textbook I'd greatly appreciate it. I find this variable transformation example in several intro mathematical probability/stats books. But I never find an intuitive explanation with it :( How do I grep for all non-ASCII characters? I have to find an easy ring which this ring is isomorphic with.  I can prove that $5 = (2+i)(2-i) \in (2+i)$ but this doesn't help me further.  My book says the answer is $\mathbb {Z_5} $ We know that in high temperature, resistivity in metals goes linearly with temperature. As temperature is lowered, resistivity goes first as $T^5$ due to "electron-phonon" interaction, and then goes as $T^2$ as temperature is further lowered due to "electron-electron" interactions.   My question is, is there an intuitive way of understanding the above power-law dependence at each temperature range physically? Elsarticle - Abstract two columns wide I am currently trying to create an article in elsarticle style, twocolumn. The title and text end up in two columns, the abstract however is made two columns wide. Any ideas what I am doing wrong? Obviously I want my abstract to also be only in the first column.  \documentclass[a4paper,10pt,twocolumn,preprint]{elsarticle}  \usepackage{lipsum}  \journal{TexExchange}   \begin{document}     \begin{frontmatter}       \title{Two-column abstract}       \begin{abstract}         \lipsum[1]      \end{abstract}       \begin{keyword}        abstract      \end{keyword}    \end{frontmatter}   \section{Outline}    \lipsum[2-3]  \end{document} How to implement a single instance Java application? LaTeX conditional expression I would like to be able to set a flag at the beginning of the main flag (say output) that tells if I want to produce a paper document or an electronic document.   Then I should check this flag to define or not empty pages, hypperref, oneside or twosides, etc.  How could I do that ? How to make number input area initially empty instead of 0 or 0.00? How to use a string column with pgfplotstable to label datapoints in a pgfplot? I have a comma-separated list of data points. They should be plotted as a scatter plot, and should be labeled using data from the .csv file. Having specified the first column of my file as string type, I still keep running into errors saying Could not parse input [...] as a floating point number, sorry.  Given a CSV file of the following format, how can I read Name and Z as labels?  Name,X,Y,Z ODIN,250,45,2001   Here is my MWE:  \documentclass{article}  \usepackage{tikz,pgfplots,pgfplotstable}     \pgfplotsset{compat=1.5.1}  \begin{document}  \pgfplotstabletypeset[columns/Name/.style={string type}]{table.csv};  \begin{tikzpicture}     \begin{axis}[     visualization depends on=\thisrow{Name} \as \labela,     visualization depends on=\thisrow{Z} \as \labelb,     every node near coord/.append style={font={\tiny}},     nodes near coords=\labela/\labelb,     nodes near coords align={horizontal},]      \addplot[only marks] table [x=X,y=Y,col sep=comma] {table.csv};      \end{axis} \end{tikzpicture}  \end{document}   Note that if the data in column Name is just floats it should work fine. Constrains relationship I have the following design. Each user has it's own contacts, it's own hosts and assign those to a domain which belongs only to him.   I want to insure that the host you assign to the domain belongs to the user that domain is assigned to.  Is it something that I have to insure in my application logic?  If I set domains.user_id foreign key to reference host.user_id and user_id.id does it eliminate my issue?    By the way can anyone suggest me a better design for my schema?