If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > loss of precision for Money datatype

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-12, 04:08
yusufn yusufn is offline
Registered User
 
Join Date: Feb 2012
Posts: 1
loss of precision for Money datatype

When working with money data type I am getting the output only upto two decimals places (rounded off) when using DBI and DBD::Sybase.

Is their a setting which can give me the output upto 4 decimals just like isql.


The code is :

#!/usr/bin/perl

use DBI;
use DBD::Sybase;

$dbh = DBI->connect("dbi:Sybase:", $ENV{"LOGNAME"}, "");
$sth = $dbh->prepare("
create table #t (mm money, ii decimal(10,4))
insert into #t(mm, ii) values(1234.4485, 45678.9898)
select mm, ii from #t
");
$sth->execute;

@row = $sth->fetchrow_array();
print join("|", @row), "\n";

output is :
1234.45|45678.9898


I can use the convert function it gives the correct output but in generic
programs using select * from table is more efficient then select col1, col2
..... from table.

modified program

#!/usr/bin/perl

use DBI;
use DBD::Sybase;

$dbh = DBI->connect("dbi:Sybase:", $ENV{"LOGNAME"}, "");
$sth = $dbh->prepare("
create table #t (mm money, ii decimal(10,4))
insert into #t(mm, ii) values(1234.4485, 45678.9898)
select convert(decimal(10, 4), mm), ii from #t
");
$sth->execute;

@row = $sth->fetchrow_array();
print join("|", @row), "\n";

output is :
1234.4485|45678.9898
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On