 |
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Thu May 01, 2008 9:11 am
Math Question, decimal truncated, want to see up to 2 decimal places |
Some math, should add up to 640 and in the end show a value of 6.40 or 6.4 but it does not, instead it shows a value of 6
| Code: |
| #alias testmath {eq_mystats=0.00;eq_mystats=(@eq_mystats+(100*0.5*2));eq_mystats=(@eq_mystats+(100*1*3));eq_mystats=(@eq_mystats+(100*0.4*3));eq_mystats=(@eq_mystats+(100*0.2*6));#show (@eq_mystats/100)} |
How do I need to do my math so that I am able to see the decimal up to 2 places |
|
|
|
 |
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Thu May 01, 2008 9:21 am |
OK strange the above example works but this one does not:
| Code: |
| #alias testmath2 {eq_mystats=(640*1.00);#show (@eq_mystats/100)} |
|
|
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu May 01, 2008 9:35 am |
Interesting. Neither %float nor %format work like they say they are supposed to.
|
|
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu May 01, 2008 9:43 am |
| Code: |
| eq_mystats=%float(640*1.00) |
Works |
|
|
|
 |
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Thu May 01, 2008 9:44 am |
well ive found a work around for the time being. change the variable type from auto to float type.. kinda annoying but it works.
|
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu May 01, 2008 9:58 am |
You're either always going to care about the decimal of a particular number or you never will, so just use %float for those numbers that you care about.
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu May 01, 2008 4:29 pm |
Doing:
#show (@eq_mystats/100.0)
will also work. If the variable is set to auto-type, then CMUD only does floating-point math if you specifically put the decimal point on the numbers (like 100.0).
Otherwise you have to set the variable to be a Float type as you mentioned. |
|
|
|
 |
|
|
|