Help, percentages without a minus sign

Want to talk about something that isn't covered by another category?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

Help, percentages without a minus sign

Post by wee wullie » Fri Oct 03, 2008 10:40 am

Hi all, I cant find a suitable thread so i posted it here , sincere apologies if i'm posting in the wrong section of this forum,
Can anyone help me with the following problem:
I'm building a report generator for work use, i'm trying to convert test scores into percentages on the report page, however, when it converts the score it comes out as a minus i.e. -75% rather than 75%, the only way i know how to do this calc is: test score = 10 (points) * 2.5 - 100 which comes out as -75% , in the test there is a maximum of 40 points that can be reached before failure, hence the multiplication x 2.5 to get 100 for calc purposes, is there any other way to do this calc which would prevent the minus from appearing.
Please help.

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Oct 03, 2008 11:10 am

So the score in the test is a negative? If I want to do well in the test, my aim is to "score" zero?

Anyway, the abs function should be a simple solution for you here. I presume there's no way that you could conceivably need a negative percentage?

percentage = abs (score * 2.5 - 100)
The Rev documentation wrote:Use the abs function if you need to know the magnitude of the number and are not concerned about whether it is negative or not.

Parameters:
The number is a positive or negative number, or any expression that evaluates to a number.

Value:
The abs function returns a positive number.

Comments:
The absolute value of a number is that number's distance from zero. If the number is positive, its absolute value is just the number; if the number is negative, its absolute value is the negative of the number. Because of this, the absolute value of a number is always positive.
(PS, you should probably have put this in the "Getting Started With..." forums)

wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

Post by wee wullie » Fri Oct 03, 2008 11:58 am

Thank you SparkOut,
i'm not entirely sure about how the syntax should be, i'm getting errors when i try to include the abs function, this is what my code looks like:
put value abs(field "PracticalResult" * 2.5 - 100) into fld "percentage"

i assume i'm missing something really obvious here, but i am fairly new to runrev and to coding in general and i'm not too good when it comes to maths as you may have realised.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Fri Oct 03, 2008 11:59 am

try:

Code: Select all

put abs(field "PracticalResult" * 2.5 - 100) into fld "percentage" 
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

Post by wee wullie » Fri Oct 03, 2008 12:13 pm

SparkOut - Your a star ,
Thank you very much for your help, that works perfectly, i'll try to move this post to the 'getting started' section as it may help someone else who has similar problems,
Once again, Thank You Very Much for all of your help, it is very appreciated, this is an excellent forum.

cheers!!!

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sat Oct 04, 2008 4:08 pm

You're welcome wee wullie (your surname isn't Harris, is it?)
I'm not that much of a star compared to many here, and after all... it was BvG who gave you the syntax for your usage. But you're right, it is an excellent forum and I'm sure that you will find lots of help here from everyone when you need it.

wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

oops

Post by wee wullie » Mon Oct 06, 2008 11:11 pm

Apologies BvG, i was in such a hurry to get my problem fixed that i didn't realise it was you who posted the solution, a big thank you and sorry about that.

And no SparkOut, my surname is Garvin , by the way, thanks for the welcome.

Post Reply