I am a bit stuck here. I am outputing the sum of int values from a database. Because the total sum is very high, it exceeded the maximum value that can fit into an int and hence the output gives me the value 2147483647 which is the maximum value of int. When I cast the sum of the int values into a "float" and output the float value, I get the value 4.067851822E9. I cannot cast the int values into "long" as sequal server doesn't accept long as a datatype. How can I convert the float value into a normal number which in my case should be 4067851822.
so the question is, what are you really trying to do, and what problem are you having?
When I cast the sum of the int values into a "float" and output the float value, I get the value 4.067851822E9. I cannot cast the int values into "long" as sequal server doesn't accept long as a datatype. How can I convert the float value into a normal number which in my case should be 4067851822.
This question comes up way too often -- and you should do a search of these forum for old topics related to this.
There is *no* formatting in a float value. The 4.067851822E9 comes from the outputting process, and not related to any formatting in the float itself. So, there is no convert of the float to anything here.
Basically, you have two options, you can fix your output code to use a format -- maybe using the printf() method instead of println() method. Or you can convert the float to something that can have a format, like a string object.
[EDIT: Beaten by a minute again ... ]
MS SQL Server does have bigint as datatype.
I am trying to output the value of the total sum of int values in a given column. Let me try and explain, basically when I run a query in MS SQL Server for the total sum of int values, I get the figure 4067856822. Since that value is very high to store as an int, I cast it as a float and when I print out the value as a float, I get the value 4.0678569E9. Now when I cast the float value into a long (by doing (long)FloatValue), I get 4067856896.
Hence I am getting different values, I simply want to get the figure 4067856822 and output that on the screen. But having problems. I am not storing the value nor doing any calculations to it.
I hope I am making sense.
If you need an exact answer like "4067856822" (10 digits), then you will not be able to put this into a float and get the exact right answer out of it. You are getting different values because the float cannot contain the exact sum with 10 digits - you get rounding errors.
So, forget about using float, and just use long (which is a 64-bit integer) to do the calculation. How are you exactly summing those numbers? Are you doing that in Java? Why exactly do you think you cannot use long?
You are 100% right.. Initially I did use long but for some strange reason, when I use long, I get the value rounded to 2147483647, which is the maximum int. I don't understand why that happens. Here is the code to my query, may be you can spot something, which I may have missed.
The last line of code gets the value as long. So here is the result I get when I set the values as long and float.
1. summaryData.setTotalCommitted(db.getLong(2)); Setting as long, I get 2147483647
2. summaryData.setTotalCommitted(db.getFloat(2)); Setting as float, I get 4.0678569E9 (which then I cast to long but then get an error in the figure)
Any Ideas or clues.. I am blank?
Thanks for your help,