|
|
|
|
|
|
| Author |
Message |
VitorEugenio *nix forums beginner
Joined: 27 Aug 2005
Posts: 1
|
Posted: Sat Aug 27, 2005 3:23 pm Post subject:
Problems converting Real to Char
|
|
|
My friends, I never worked with RDb before, but I developed a software
using Oracle 9i and now I had to use RDB... and I'm having lots of
problems.
I have a column declared as REAL and another one as Char, I need to put
them toguether in a string.
Ex.: Field - Number (REAL) Value: 100.02
Field - Mesure (char) Value: "m2"
I have to make a SELECT and return like this "100,02 m2"
When I was using oracle 9i I just put "table.number || '-' ||
table.mesure" and it was perfect... but with RDB I can't use this way,
I have to convert REAL in CHAR first, but when I do this the result is
something like that: "1.020000000E m2" completely diferent, how can I
solve this?
ps.: If I use "cast(Cast(table.number as integer) as varchar(10)) ||
'-' || table.mesure " it works but losing precision...
Please, it seems to be a stupid question.. but I never worked with this
database before and I'm very lost....
tnks... |
|
| Back to top |
|
 |
Dr. Dweeb *nix forums Guru Wannabe
Joined: 23 Jul 2005
Posts: 125
|
Posted: Fri Nov 04, 2005 10:03 pm Post subject:
Re: Problems converting Real to Char
|
|
|
VitorEugenio wrote:
| Quote: | My friends, I never worked with RDb before, but I developed a software
using Oracle 9i and now I had to use RDB... and I'm having lots of
problems.
I have a column declared as REAL and another one as Char, I need to
put
them toguether in a string.
Ex.: Field - Number (REAL) Value: 100.02
Field - Mesure (char) Value: "m2"
I have to make a SELECT and return like this "100,02 m2"
When I was using oracle 9i I just put "table.number || '-' ||
table.mesure" and it was perfect... but with RDB I can't use this way,
I have to convert REAL in CHAR first, but when I do this the result is
something like that: "1.020000000E m2" completely diferent, how can I
solve this?
ps.: If I use "cast(Cast(table.number as integer) as varchar(10)) ||
'-' || table.mesure " it works but losing precision...
Please, it seems to be a stupid question.. but I never worked with
this
database before and I'm very lost....
tnks...
|
I had that problem once, sadly I cannot remember how I solved it and I am
not near a machine right now. I will try and have a look at it next week.
Dr. Dweeb |
|
| Back to top |
|
 |
Richard Maher *nix forums Guru Wannabe
Joined: 15 Jun 2005
Posts: 275
|
Posted: Fri Nov 04, 2005 11:58 pm Post subject:
Re: Problems converting Real to Char
|
|
|
Hi,
| Quote: | something like that: "1.020000000E m2" completely diferent,
|
But that's what floating point numbers look like isn't it?
| Quote: | ps.: If I use "cast(Cast(table.number as integer) as varchar(10)) ||
'-' || table.mesure " it works but losing precision...
|
You could always use a scaled integer (For example INTEGER(2)) for two
decimal places or ((table.number + 0.005) as integer(2)) But if you knew it
had two decimal places then I guess you wouln't be storing it as a real?
Regards Richard Maher
PS. If all else fails you could always right an external function to do
whatever conversion activities that you'd like. I'd suggest picking a
language that doesn't support scaled integers and then finding the
appropriate CPU-burning subroutine in that languages run-time library. Then,
at least, the output will be consistent (whether right or wrong).
"Dr. Dweeb" <NOSPAM_5msg0h202@sneakemail.com> wrote in message
news:436bdac9$0$78279$157c6196@dreader1.cybercity.dk...
| Quote: | VitorEugenio wrote:
My friends, I never worked with RDb before, but I developed a software
using Oracle 9i and now I had to use RDB... and I'm having lots of
problems.
I have a column declared as REAL and another one as Char, I need to
put
them toguether in a string.
Ex.: Field - Number (REAL) Value: 100.02
Field - Mesure (char) Value: "m2"
I have to make a SELECT and return like this "100,02 m2"
When I was using oracle 9i I just put "table.number || '-' ||
table.mesure" and it was perfect... but with RDB I can't use this way,
I have to convert REAL in CHAR first, but when I do this the result is
something like that: "1.020000000E m2" completely diferent, how can I
solve this?
ps.: If I use "cast(Cast(table.number as integer) as varchar(10)) ||
'-' || table.mesure " it works but losing precision...
Please, it seems to be a stupid question.. but I never worked with
this
database before and I'm very lost....
tnks...
I had that problem once, sadly I cannot remember how I solved it and I am
not near a machine right now. I will try and have a look at it next week.
Dr. Dweeb
|
|
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Tue Dec 02, 2008 5:55 pm | All times are GMT
|
|
MPAA | France Hotels | Mobile Phone | Loan | Mortgages
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|