Sunday, February 19, 2012

I need help with Float datatype

I have a breakAmt field in my table that is a float datatype. The values
need to be in hours. So if employeeA took a break for 1 minute it should be
0.016. If EmployeeB had a 19 minute break it should be 0.316. If EmpC took
a 3 minute break I get the value 5.0000000000000003E-2. How can I convert
this to leave out the E-2'
The reson I need to maintain a float is because I need to extract these
values to a foxpro table that requires a float field. If I use a decimal
instead will the export bomb'
Thanks,
NinelIIRC the FLOAT datatype in FoxPro is an exact numeric, not at all the
same as SQL Server's FLOAT, which is an approximate floating point
type. I see no reason why you need to use FLOAT for this in SQL Server,
whatever the type in FoxPro.
If you want exact values then use an exact numeric datatype. If you
just want to *display* the value differently then do that in your
client application.
David Portas
SQL Server MVP
--|||According to
http://msdn.microsoft.com/library/e...pes.as
p
FoxPro's [float] is the same as FoxPro's [numeric], which looks
like a "floating" decimal to me. To cover the FoxPro range of
scale and precision use SQL Server's NUMERIC(30,10). If you
do not need this much range or precision, scale down to
NUMERIC(28,X) or NUMERIC(19,X), where X is the maximum
number of places after the decimal point you need.
Using 28 avoids some quirky things due to internal calculations
using 64-bit floating point values (I think), and also saves 4 bytes
per value. Using 19 saves yet another 4 bytes.
Steve Kass
Drew University
ninel gorbunov via webservertalk.com wrote:

>I have a breakAmt field in my table that is a float datatype. The values
>need to be in hours. So if employeeA took a break for 1 minute it should be
>0.016. If EmployeeB had a 19 minute break it should be 0.316. If EmpC took
>a 3 minute break I get the value 5.0000000000000003E-2. How can I convert
>this to leave out the E-2'
>The reson I need to maintain a float is because I need to extract these
>values to a foxpro table that requires a float field. If I use a decimal
>instead will the export bomb'
>Thanks,
>Ninel
>|||Take a look at the following script:
use pubs
go
declare @.fr float,@.fn float
set @.fn = 1
set @.fr=(@.fn/60)
print (@.fn/60)
set @.fn = 19
set @.fr=(@.fn/60)
print (@.fn/60)
set @.fn = 3
set @.fr=(@.fn/60)
print (@.fn/60)
go
HTH,
Thanks
ZULFIQAR SYED
http://zulfiqar.typepad.com
MCP
"ninel gorbunov via webservertalk.com" wrote:

> I have a breakAmt field in my table that is a float datatype. The values
> need to be in hours. So if employeeA took a break for 1 minute it should b
e
> 0.016. If EmployeeB had a 19 minute break it should be 0.316. If EmpC took
> a 3 minute break I get the value 5.0000000000000003E-2. How can I convert
> this to leave out the E-2'
> The reson I need to maintain a float is because I need to extract these
> values to a foxpro table that requires a float field. If I use a decimal
> instead will the export bomb'
> Thanks,
> Ninel
>

No comments:

Post a Comment