473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

exponential

if i am building a console application, what code should i us to make
an exponential operation?

For example 4^2 = 8

If i use the ^ symbol, i get an error

thanks

Sep 1 '07 #1
7 3856
Math.Pow?

Sep 1 '07 #2
On Sep 1, 5:44 pm, Marc Gravell <marc.grav...@gmail.comwrote:
Math.Pow?
how?

deciaml a = 4;
decimal b = 3;

then?

Sep 1 '07 #3
vinnie wrote:
On Sep 1, 5:44 pm, Marc Gravell <marc.grav...@gmail.comwrote:
>Math.Pow?

how?

deciaml a = 4;
decimal b = 3;

then?
Math.Pow(a,b) works for double, int etc. but not for
decimal.

If the second argument really is decimal, then I think you will
need to convert to double, pow and then convert the result back.

If the second argument is really an integer (which seems more
likely), then you can easily write your own Pow.

Arne

Sep 1 '07 #4
vinnie <ce**********@gmail.comwrote:
On Sep 1, 5:44 pm, Marc Gravell <marc.grav...@gmail.comwrote:
Math.Pow?

how?

deciaml a = 4;
decimal b = 3;

then?
There's nothing in the framework that provides powers for decimals.
You'd have to use doubles instead. You can cast back to decimal
afterwards, of course.

decimal a = 4;
decimal b = 3;

decimal x = (decimal) Math.Pow((double)a, (double)b);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 1 '07 #5
"vinnie" <ce**********@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
>Math.Pow?

how?

deciaml a = 4;
decimal b = 3;

then?
double a = 4;
double b = 3;
double c = Math.Pow(a, b); // == 4^3

http://msdn2.microsoft.com/en-us/lib...ow(vs.80).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 1 '07 #6
maybe the error is the operation you are applying

The odd thing is: I didn't even look at the math! (and I'm normally a
pedant...)

Good spot ;-p

Marc

Sep 2 '07 #7
The odd thing is: I didn't even look at the math! (and I'm normally a
pedant...)
Not as pedant as me! :-)
Sep 3 '07 #8

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

Similar topics

1
by: Ryoga | last post by:
How can I print out the value of a large double in plain decimal form without the exponential notation? For example (quick code): PlainPrint.java: --------------- public class PlainPrint {...
4
by: Timothy Fitz | last post by:
Why are all numberical literals in exponential notation floats? To me it is counter-intuitive for 1e3 to behave so fundamentally different from 1000. Timothy Fitz
1
by: Mahesha | last post by:
Exponential Moving avg is calculated using the formula. EMA = (Today's Price)* K + (EMA yesterday) * (1-K) where K = 2 / (N+1) The user is going to Input the K. It is something like F(N) =...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
8
by: Martin Jørgensen | last post by:
Hi, I have a program that reads in a couple of numbers from files and then stores them with some latex-code but I'm not satisfied with the exponential output, as it takes up too many character...
2
by: Poz | last post by:
Is there a way to convert an exponential number (held in string format) to non-exponential format without losing any precision in the number? For example, I have a string variable containing...
4
by: b4ukiran | last post by:
Hi all, I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I...
3
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as...
1
by: pankajprakash | last post by:
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.