I'm trying to use the std::map where the is double or float up to the third digit after the decimal point, my problem is how to system save the double number when I'm entering 9.20 some time is saved as 9.199999 and then the find function is not working. is there a way to make it work or just use ints or strings as key?
27
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
78703
If have this in the setter of a property:  decimal? temp = value as decimal?;   value = "90"  But after the cast, temp is null...  What is the proper way to do this cast?
73742
What is the best way to handle large numeric inputs in C++ (for example 10^100)?   For algorithms I usually switch over to ruby and I sometimes use strings.  Any other good methods?
70367
I spent 3 hours trying to write a command to format a time (duration) expressed as a floating number (in seconds) in a nice form as follows:  if the time is &lt; 60 write as a float with 3 decimals (i.e. milliseconds)  else let h,m,s be the hours, minutes and seconds corresponding to the time      if h=0 then write as m:ss (ss always with 2 digits, m can have only 1)      else write h:mm:ss (mm and ss with 2 digits, h can have only 1)   So 1.25678 gives 1.256, 125.35 gives 2:05, 18249 (which equals to 5*3600+4*60+9) gives 5:04:09.  I tried several packages for the comparison/formatting. No success. Can someone help me ? Thanks !
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).
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
33779
I came across some very strange behaviour when working with a Map with Decimal keys today. It seems like the Decimal type can't handle Integer assignments properly, but allows them nonetheless. I've written some example code demonstrating the problem:  Map&lt;Decimal, String&gt; m = new Map&lt;Decimal, String&gt;(); m.put(1234, 'Integer key');  m.put(1234.0, 'Decimal key'); m.put(1234.5, 'Decimal Unique key');  System.debug(m.get(1234));      // =&gt; Integer key, why was this not overwritten if 1234 == 1234.0? System.debug(m.get(1234.0));    // =&gt; Decimal key System.debug(m.get(1234.5));    // =&gt; Decimal Unique key  System.debug(m);        //Order of insertion matters, newest value does not override existing one but is not shown on map printout... for(Decimal d : m.keySet()){     System.debug(d);    //...unless you print it out yourself, because this loop shows all the keys }  //Sanity check System.debug(1234 == 1234.0); //True  //Digging deeper Decimal fake_d = 1234; Decimal real_d = 1234.0; Integer real_i = 1234; //Integer fake_i = 1234.0; //Illegal assignment, typechecking only works one way, it seems  //More sanity checks System.debug(fake_d == real_d); //True (Except when used in a Map, apparently) System.debug(fake_d == real_i); //True  System.debug(m.get(real_i)); // =&gt; Integer key System.debug(m.get(fake_d)); // =&gt; Integer key, even with fake_d explicitely declared as a Decimal type, it still pretends to be an Integer. System.debug(m.get(real_d)); // =&gt; Decimal key   I found this behaviour when I tried to fetch a value from a map using a Decimal sObject field, only to find that the keys I used to populate the Map (coming from a different Decimal field) were interpreted as Integers since they had no real decimal digits.  Maybe using Decimals as Map keys is not supported for some reason? Is it expected behaviour for 1234 and 1234.0 being distinct values in this case or is this an oversight in the Map implementation?
60608
I have the value 25.00 in a float, but when I print it on screen it is 25.0000000. How can I display the value with only two decimal places?
28516
How do I format a number in Java? What are the &quot;Best Practices&quot;? Will I need to round a number before I format it?  32.302342342342343 =&gt; 32.30 .7323 =&gt; 0.73  etc.
27536
I wish to calculate the time it took for an API to return a value. The time taken for such an action is in the space of nanoseconds. As the API is a C++ class/function, I am using the timer.h to calculate the same:   #include &lt;ctime&gt;   #include &lt;iostream&gt;    using namespace std;    int main(int argc, char** argv) {        clock_t start;       double diff;       start = clock();       diff = ( std::clock() - start ) / (double)CLOCKS_PER_SEC;       cout&lt;&lt;&quot;printf: &quot;&lt;&lt; diff &lt;&lt;'\n';        return 0;   }  The above code gives the time in seconds. How do I get the same in nano seconds and with more precision?
70051
How can I format Floats in Java so that the float component is displayed only if it's not zero? For example:   123.45 -> 123.45 99.0   -> 99 23.2   -> 23.2 45.0   -> 45   Edit: I forgot to mention - I'm still on Java 1.4 - sorry!
90637
Excel converting value 0503E000 to 5.03E+02 in any cell automatically in CSV I tried to convert it to text number and general but after i save it and reopen it again it goes back to 5.03E+02  How do I stop this from happening?
124293
I recently installed Windows 10 (upgrade from 7). It is an English version Windows, which I configured to the German locale(*), which uses a comma (",") instead of a dot (".") as the decimal separator, i.e. the number Pi is 3,14 not 3.14.   This works fine in Excel. However, it does NOT in the standard Windows calculator, which simply IGNORES a comma key press COMPLETELY. If I use a dot, it produces a dot which works as a decimal separator (which is wrong).  Note that I'm talking about the actual comma key here, not the numpad comma, which works fine but produces a dot in the Calculator (it produces a comma in Excel!).  My question: Does anyone have any ideas how to get Calculator to respect the German locale and recognize the comma key and display a comma?  (*) Control Panel > Change date, time, or number formats > Format: German (Germany). Under additional settings, the decimal separator is correctly set to ",".
113958
I've heard many people say that if the number of expected elements in the container is relatively small, it is better to use std::vector instead of std::map even if you were to use the container for lookups only and not iterating.  What is the real reason behind this?  Obviously the lookup performance of std::map cannot be worse than std::vector (although it may differ in nanoseconds/microseconds) so does it have something to do with memory usage?  Does std::vector fare any better/worse than std::map in fragmenting the virtual address space?  I am using the STL library that comes along with Visual Studio (i.e. Microsoft's implementation).  Does that make any difference compared to other implementations?
80880
My code:  a = '2.3'   I wanted to display a as a floating point value.  Since a is a string, I tried:  float(a)   The result I got was :  2.2999999999999998   I want a solution for this problem. Please, kindly help me.  I was following .
96280
How do I map numbers, linearly, between a and b to go between c and d.  That is, I want numbers between 2 and 6 to map to numbers between 10 and 20... but I need the generalized case.  My brain is fried.
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?