Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a real value to a string or integer?! How?!

Status
Not open for further replies.

carpetbelly

Technical User
Jun 12, 2003
202
GB
Ok, quite a newbie to OO coding, and coding in general but I have picked it up ok.

Currently I am struggling with the fact I have some data being read in as a real value and has to be. I am requiring the last two digits of this data. I have basically two ways I know of and can do of obtaining these digits.

Multiplying my number by 100 (to make it a whole number rather than to 2dp) then use the DIV function (factor of 100) to get the number without DP. Then subtract that from my original number4. Unfortunately the DIV function requires my number as an integer rather than the 'real' format it was read in as.

Or i could use a string function and read in negatively (so from right to left) or go algabraeic and do something like

(lengthn) - (lengthn - 2) and use that as my starting position for a substring.

Any ideas on how I can get to these positons would be more than helpful!!!

Thanks!!!

 
If you tell us what language you are tring to use it would be much easier.
The principle is simple:
(value - (int)value)*100
Do you need to consider rounding issues? Round up, down? Round to nearest?




(very injured) Trojan.
 
It's a program called AION which uses a Java based language. Unfortunately it doesn't like casts and yes the principle you have put up would work fine for Java this program is not liking it at all as the initial value is a real value.

Defo appriciate the help though!!! :eek:)
 
The "(int)value" might be a function, not a cast so it might be "int(value)".
I'll see if I can find anything about AION.

Trojan.



(very injured) Trojan.
 
AION is a rule based expert system. It's a programming language, Jim, but not as we know it...
 
done... asked them. Not possible but they put me in another direction on how to do what I was after.

*hangs head in shame* round function. Doh! Mainly as I am after a fixed number and it has to match as either a true or false so 'ROUND' works fine for me.

And I was also told of the TRUNK function or maybe even reading it in as a CHAR() and reading from right to left (so negatively in).

Just in case anyone else gets a similar issue, thats why the details all there above.

Think I was just having one of those weeks!
 
FYI: If you are paraphrasing what the folks at AION told you OVER THE PHONE, and if you ever need it, it's probably TRUNC (not TRUNK). TRUNC is short for "truncate" and merely drops everything decimal point, on. Of course, it might be that in this funny language, TRUNK is how it's done. I just like to hear the sound of my keyboard clicking! :)

--Dave
 
quite funny but I did ask that as I did assume that. Having now looked in the system you are of course right and it makes far more sense that way round.

Maybe I just didnt understand his accent very well as it was a very heavy German accent and I can rush my talking and panic people quite easily.

And who doesn't like loud clicky kerboards! Makes you sound like you're working really really hard when on forums and the like.

Obviously I do work really really hard :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top