473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a String an Int [solved]

24 New Member
Hi! My problem is that im trying to make an Int out of the string a=X+Y*Z-A/B... (for example 1-2+6-3*2/3-3). when i do Int(a) it doesn't work beacuse of the (+,-,/,*)

What should i do?
Oct 29 '06 #1
6 4050
bvdet
2,851 Recognized Expert Moderator Specialist
Hi! My problem is that im trying to make an Int out of the string a=X+Y*Z-A/B... (for example 1-2+6-3*2/3-3). when i do Int(a) it doesn't work beacuse of the (+,-,/,*)

What should i do?
Would something like this work for you?
Expand|Select|Wrap|Line Numbers
  1. x,y,z,w = 3.0,12,16,4.5
  2. a='x+y*z-w/x'
  3. print eval(a)
  4. print int(eval(a))
  5.  
Oct 29 '06 #2
MaxLindquist
24 New Member
Yes... thank you very much
Oct 29 '06 #3
bartonc
6,596 Recognized Expert Expert
Would something like this work for you?
Expand|Select|Wrap|Line Numbers
  1. x,y,z,w = 3.0,12,16,4.5
  2. a='x+y*z-w/x'
  3. print eval(a)
  4. print int(eval(a))
  5.  
or get the floating point (since they're in the formula) by:

Expand|Select|Wrap|Line Numbers
  1. print eval(a)
  2.  
Oct 29 '06 #4
MaxLindquist
24 New Member
What if i want the calculation to skip the usual rules, so that x+y*z-a/b is like ((((x+y)*z)-a)/b)?
Oct 29 '06 #5
bartonc
6,596 Recognized Expert Expert
What if i want the calculation to skip the usual rules, so that x+y*z-a/b is like ((((x+y)*z)-a)/b)?
Use the parens in the string or break it up and eval pieces at a time.
Sounds like you're working on some sort of language parser...
What's the project about? One of my early projects was an assembler for moto micros. Keep posting,
Barton
Oct 29 '06 #6
MaxLindquist
24 New Member
Im making a dicegame. I'm an absoulte beginner and i am not very good with computers, so a am very thankful for your help!
Oct 29 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3600
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
10
2861
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
13
2521
by: Niyazi | last post by:
Hi I have a report that I have to run it monthly in my machine. My code in VB.NET and I access AS400 to get data, anaysie it and send into pre formated Excel sheet. The data consist of 9000...
1
1493
by: beachboy | last post by:
My project has many class (function), it need to create a new instance each time by the id value, how can i write a code as much simple? Actually, all cases is doing the same thing.... , but is...
14
4250
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
19
2411
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
1
1524
by: carly | last post by:
Hi all, I have been working on a quesstion, i have solved parts a up to c, but im having trouble with part d and e, any tips on how i can solve them would be very much appreaciated. I'd also...
5
9207
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of...
4
1078
by: Mikael Syska | last post by:
Hi, I have a problem ...: If you look at http://syska.dk/upload/eb-14.jpeg you can see some names to the right ... Alexandro, syska, resurrected. I want an option to pick a new color for the...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.