Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Cast a type real into a string
Topic Summary:
Created On: 9-Mar-2007 08:47
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Reik Schroeder, on Friday, March 9, 2007 10:53 AM

Answer:
Hi Lucian,

I think you need to convert the integer values into real value before doing the arithmetics.

So you would get:
int a = 1;
int b = 44;
real ab = realOf (a) / realOf (b);

or if you have fixed numbers:
real ab = 1.0/44.0;

The .0 shows the interpreter that you want to have real numbers instead of integer.

Hope that helps you.

Greetings
Reik
 9-Mar-2007 08:47
User is offline View Users Profile Print this message


Lucian Bodron

Posts: 24
Joined: 12-Oct-2005

Hello,

I have searched inside the forum, but I haven't seen a solution to my problem.

I have a real type variable and I want to put it into a string so I can send it to an out text file. It works if I just print it, but I don't want that. I need to convert it into a string somehow.

Can it be done?

And in addition, if I want to have the result of (int x/int y) what should I use?
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 08:51
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Hi Lucian,

that ist really simple if you now how

You can convert numbers and dates into strings by appending an empty string:
real r = 1.0;
string s = r"";

Greetings
Reik

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 10:00
User is offline View Users Profile Print this message


Lucian Bodron

Posts: 24
Joined: 12-Oct-2005

Hi Reik,

It worked, thank you very much.

But can you answer also to the second question? I need to see the corect and full result when dividing 2 int variables.

For ex. I have to divide 1 to 44. The expected result should have been 0.022727272, but I only get 0.0000. How can I get the full result?
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 10:42
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Answer Answer
Hi Lucian,

I think you need to convert the integer values into real value before doing the arithmetics.

So you would get:
int a = 1;
int b = 44;
real ab = realOf (a) / realOf (b);

or if you have fixed numbers:
real ab = 1.0/44.0;

The .0 shows the interpreter that you want to have real numbers instead of integer.

Hope that helps you.

Greetings
Reik

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 10:46
User is offline View Users Profile Print this message


Paul Worrall

Posts: 87
Joined: 30-Sep-2003

Integer division in DXL always rounds the result down to give an integer result, e.g. 1/44 and 43/44 both give 0. To get a real result, you should use real division by converting the operands to reals, e.g. (realOf 43)/(realOf 44) gives 0.977273
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 10:54
User is offline View Users Profile Print this message


Lucian Bodron

Posts: 24
Joined: 12-Oct-2005

Thank you Reik,

It worked very nice!

Much appreciated
Report this to a Moderator Report this to a Moderator
 9-Mar-2007 12:25
User is offline View Users Profile Print this message


Lucian Bodron

Posts: 24
Joined: 12-Oct-2005

Thank you too Paul. Nice explanation . I will keep that in mind!

Edited: 9-Mar-2007 at 12:26 by Lucian Bodron
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.