dbTalk Databases Forums  

Problems converting Real to Char

comp.databases.rdb comp.databases.rdb


Discuss Problems converting Real to Char in the comp.databases.rdb forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
VitorEugenio
 
Posts: n/a

Default Problems converting Real to Char - 08-27-2005 , 12:23 PM






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...


Reply With Quote
  #2  
Old   
Dr. Dweeb
 
Posts: n/a

Default Re: Problems converting Real to Char - 11-04-2005 , 04:03 PM






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




Reply With Quote
  #3  
Old   
Richard Maher
 
Posts: n/a

Default Re: Problems converting Real to Char - 11-04-2005 , 05:58 PM



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 (AT) sneakemail (DOT) com> wrote

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





Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.