![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
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 |
![]() |
![]()
|
![]() 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 | |
![]() |
|
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? |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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? |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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
|
|
![]() |
|
![]() |
|
Thank you Reik,
It worked very nice! Much appreciated ![]() |
|
![]() |
|
![]() |
|
Thank you too Paul. Nice explanation
![]() Edited: 9-Mar-2007 at 12:26 by Lucian Bodron |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Cast a type real into a string
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.