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

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

Thread Next
From:
Fennell, Brian
Date:
December 20, 2021 15:14
Subject:
RE: [EXTERNAL] Re: select decimal column from mysql
Message ID:
MN2PR14MB32948655FED9E0824B9C74C7A27B9@MN2PR14MB3294.namprd14.prod.outlook.com
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 Next


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