I am trying to format add a zero to any value less than 10, so 09. So at the end of the loop, the "total" value will format to numbers less than 10 with a zero.  Here is my code but it still isn't working :  int total = 0;  String holder = val + "-" + s + "-" + frame + "-";     for (int i = 0; i &lt; holder.length(); i++)     {         int mod = holder.charAt(i);         total += mod;         total = total%100; //get remainder     }  string totalchk = String.format("%02d", total);
271
How do you left pad an int with zeros when converting to a String in java?  I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
44860
I am looking to format a number like 188518982.18 to £188,518,982.18 using Python.  How can I do this?
3152
I have over 6000 records and half of them are formulas that are missing a variable so they result in #N/A on the spreadsheet, what i want to do is if the cell is #N/A then leave the cell blank, otherwise print a string like so  =IF(AR6347="#N/A","","string in here")   But this does not work with ="#N/A", is there a way to do this?
33306
Hey! I was looking at this code at   I noticed that in some situations they used hex numbers, like in line 134:  for (j = 1; val &amp;&amp; j &lt;= 0x80; j &lt;&lt;= 1, q++)   Now why would they use the 0x80? I am not that good with hex but I found an online hex to decimal and it gave me 128 for 0x80.  Also before line 134, on line 114 they have this:  small_n = (n &amp; 0xffff0000) == 0;   The hex to decimal gave me 4294901760 for that hex number. So here in this line they are making a bit AND and comparing the result to 0??  Why not just use the number? Can anyone please explain and please do give examples of other situations.  Also I have seen large lines of code where it's just hex numbers and never really understood why :(
10097
Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input.
55076
How do you convert a number to a string showing dollars and cents?  eg: 123.45    =&gt; '$123.45' 123.456   =&gt; '$123.46' 123       =&gt; '$123.00' .13       =&gt; '$0.13' .1        =&gt; '$0.10' 0         =&gt; '$0.00'
117305
I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.
4499
I'm trying to find a good way to print leading 0, such as 01001 for a . While the number would be stored as 1001, what is a good way to do it? I thought of using either case statements or if to figure out how many digits the number is and then convert it to an char array with extra 0's for printing, but I can't help but think there may be a way to do this with the printf format syntax that is eluding me.
19059
is there a way to pass a string to the &lt;apex:outputText&gt; so that it can be formatted as a currency or percent value?  Here's what I have inside a column of my visual force table:  &lt;apex:outputText value="{0, number, currecny}"&gt; &lt;apex:param value="{!row.values[1]}" /&gt; &lt;/apex:outputText   this gives me an error at runtime (when the visual force page loads), which I think may be some kind of type mismatch, where &lt;apex:outputText&gt; is expecting a Decimal or number but I am passing a string.  This is the error at runtime:     The value attribute on  is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.   Thanks
36269
In .NET why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision.
80203
This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don's see any reason for it to be sending an error on this instance and not the four previous ones. Reference the code below, and feel free to provide any criticism you may have as it should make me better. If it matters, I am using Sharp Develop 2.2.  Here is an example of the code that works:  void calc2Click(object sender, EventArgs e) {     if (!String.IsNullOrEmpty(tb2_fla.Text) &amp; String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) &amp; String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text))     {         MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);     }                 if (!String.IsNullOrEmpty(tb2_kva.Text) &amp; !String.IsNullOrEmpty(tb2_e.Text))     {              decimal x, y, z;             x = decimal.Parse(tb2_kva.Text);                   y = decimal.Parse(tb2_e.Text);             z = (x * 1000) / (1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals                 tb2_fla.Text = z.ToString();             tb2_fla.Text = Math.Round(z,2).ToString();     }         else     {         if (!String.IsNullOrEmpty(tb2_fla.Text) &amp; !String.IsNullOrEmpty(tb2_e.Text))     {              decimal x, y, z;             x = decimal.Parse(tb2_fla.Text);                   y = decimal.Parse(tb2_e.Text);             z = (x * y * 1.732050808m) / 1000; //the m at the end of the decimal allows for the multiplication of decimals               tb2_kva.Text = Math.Round(z,2).ToString();      }   Here is the example of the code that sends the error in the subject line of this post:  void Calc4Click(object sender, EventArgs e) {         if (!String.IsNullOrEmpty(tb4_fla.Text) &amp;&amp; String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) &amp; String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text))         {   //If values are entered improperly, the following message box will appear         MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);         }              if (!String.IsNullOrEmpty(tb4_fla.Text)&amp;&amp; !String.IsNullOrEmpty(tb4_e.Text)&amp;&amp; String.IsNullOrEmpty(tb4_kw.Text))         {//If the user eneters FLA and Voltage calculate for kW              decimal x, y, z;             x = decimal.Parse(tb4_fla.Text);             y = decimal.Parse(tb4_e.Text);             z = (x*y)*(.8 * 1.732050808m);             tb4_kw.Text = Math.Round(z,0).ToString();          }                         if (!String.IsNullOrEmpty(tb4_kw.Text) &amp;&amp; !String.IsNullOrEmpty(tb4_e.Text) &amp;&amp; String.IsNullOrEmpty(tb4_fla.Text))         {;//If the user enters kW and Voltage calculate for FLA             decimal x, y, z;             x = decimal.Parse(tb4_kw.Text);             y = decimal.Parse(tb4_e.Text);             z = (1000 * x)/(y * 1.732050808m)* .8;             tb4_fla.Text = Math.Round(z,0).ToString();         }      }   I appreciate any help that I can get.  Thank you.
99569
Is there a way to write binary literals in C#, like prefixing hexadecimal with 0x? 0b doesn't work.  If not, what is an easy way to do it? Some kind of string conversion?
18458
How to make enumerate list format numbers like this:     REG/001 (content)      REG/002 (content)      REG/003 (content)   I already managed to do the following:   \begin{enumerate}[label=\textbf{REG/\arabic*},leftmargin=*] \item content \end{enumerate}   using   \usepackage{enumitem}   but I don't know how to add leading zeros.
75120
In a visual force page, I can take a date and do this...  &lt;apex:outputText value="{0,date, MMMM d,  yyyy}"&gt;     &lt;apex:param value="{!relatedTo.my_date__c}"/&gt; &lt;/apex:outputText&gt;   I want to be able to do that in Apex code.  So I want a method which takes a date and returns a certain format as a string.  I check the API:   and sorry if I am stupid but not so obvious how to do this?  Many thanks.
26280
What is an easy way in Python to format integers into strings representing thousands with K, and millions with M, and leaving just couple digits after comma?  I'd like to show 7436313 as 7.44M, and 2345 as 2,34K.  Is there some % string formatting operator available for that? Or that could be done only by actually dividing by 1000 in a loop and constructing result string step by step?
32081
I am working on a SQL query that reads from a SQLServer database to produce an extract file. One of the  requirements to remove the leading zeroes from a particular field, which is a simple VARCHAR(10) field. So, for example, if the field contains '00001A', the SELECT statement needs to return the data as '1A'.  Is there a way in SQL to easily remove the leading zeroes in this way? I know there is an RTRIM function, but this seems only to remove spaces.
4701
How do I generate a random int value in a specific range? I have tried the following, but those do not work: Attempt 1: randomNum = minimum + (int)(Math.random() * maximum);  Bug: randomNum can be bigger than maximum. Attempt 2: Random rn = new Random(); int n = maximum - minimum + 1; int i = rn.nextInt() % n; randomNum =  minimum + i;  Bug: randomNum can be smaller than minimum.