develooper Front page | perl.dbi.users | Postings from December 2021

RE: [EXTERNAL] Re: select decimal column from mysql

Thread Previous
From:
Fennell, Brian
Date:
December 20, 2021 16:49
Subject:
RE: [EXTERNAL] Re: select decimal column from mysql
Message ID:
MN2PR14MB3294CD7E7B28795FA8617CC1A27B9@MN2PR14MB3294.namprd14.prod.outlook.com
Before someone points out that my description of perl variables is incomplete:

Here are the extra details for the very curious:

https://perldoc.perl.org/perlguts#Datatypes

https://metacpan.org/pod/Scalar::Util

https://perldoc.perl.org/Scalar::Util#dualvar

https://perldoc.perl.org/Scalar::Util#isdual

https://perldoc.perl.org/Scalar::Util#isvstring

https://perldoc.perl.org/Scalar::Util#looks_like_number

https://metacpan.org/release/NWCLARK/perl-5.8.8/view/pod/perlapi.pod

https://metacpan.org/pod/POSIX::1003::Math

https://www.perl.com/pub/2012/06/perlunicook-further-resources.html/

https://perldoc.perl.org/perlapi

https://perldoc.perl.org/perlembed

https://perldoc.perl.org/Devel::Peek

https://www.nntp.perl.org/group/perl.perl5.porters/2015/11/msg232974.html




-----Original Message-----
From: Fennell, Brian
Sent: Monday, December 20, 2021 10:14 AM
To: john miky <gb2313@gmail.com>; dbi-users@perl.org
Subject: RE: [EXTERNAL] Re: select decimal column from mysql

Variables in perl are “untyped” or better yet “dynamically typed”.
Every variable is a string but will behave like a int or float in the right context.
Conversions from string to int to float and back to string happen automatically and silently.
This may be surprising and confusing if you are coming from java.

Example:

perl -e '$v = "123" ; print $v . "\n" ; $v += 2 ; print $v . "\n"; $v /= 2.0 ; print $v . "\n"; print length($v) . "\n"; $v = "(" . $v . ")"; print $v . "\n"'
123
125
62.5
4
(62.5)



From: john miky <gb2313@gmail.com>
Sent: Monday, December 20, 2021 1:28 AM
To: dbi-users@perl.org
Subject: [EXTERNAL] Re: select decimal column from mysql

sorry, please ignore this stupid question, 0.015 is > 0

On Mon, Dec 20, 2021 at 2:19 PM john miky <mailto:gb2313@gmail.com> wrote:
hmm. it is perl's "problem", not dbi.

On Mon, Dec 20, 2021 at 1:20 PM john miky <mailto:gb2313@gmail.com> wrote:
hi,

I select a decimal column, from mysql with dbi, the value 0.015 for example,  my ($v) = $dbh->selectrow_array("select price from test limit 1") it is greater than 0 in perl.

What's the proper way to get a float value ?



The information contained in this electronic mail transmission is intended only for the use of the individual or entity named in this transmission. If you are not the intended recipient of this transmission, you are hereby notified that any disclosure, copying or distribution of the contents of this transmission is strictly prohibited and that you should delete the contents of this transmission from your system immediately. Any comments or statements contained in this transmission do not necessarily reflect the views or position of Radial or its subsidiaries and/or affiliates.



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About