Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:15 02 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : howto calc whit the %

Author Message
tenij000
Regular Member

Joined: 30/05/2025
Location: Netherlands
Posts: 51
Posted: 09:30am 07 Aug 2025
Copy link to clipboard 
Print this post

how do i calc whit the %

most is working whit this program

cls
font 3
' === Elementen ===
GUI TEXTBOX    #1,  20,  20, 200, 30, RGB(0,0,0), RGB(255,255,255) ' Invoerveld
GUI BUTTON     #2, "Bereken", 20, 120, 80, 30, RGB(0,0,0), RGB(0,255,0) ' Knop
GUI DISPLAYBOX #3,  20,  70, 200, 30, RGB(0,0,0), RGB(220,220,220) ' Resultaat

' === Hoofdlus ===
DO
 IF CtrlVal(#2) = 1 THEN
   expr$ = CtrlVal(#1)
   ON ERROR SKIP
   result = EVAL(expr$)
   CtrlVal(#3) = STR$(result)
   CtrlVal(#2) = 0
 ENDIF
 PAUSE 50
LOOP
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 09:57am 07 Aug 2025
Copy link to clipboard 
Print this post

I would like to help, but unfortunately I don't understand your problem. Please, can you explain in more detail what the program is supposed to do and what you need as a percentage.

How to calculate percentages:

A percentage is a way to express a number as a part of 100.
To calculate a percentage, use this formula:

👉 (Part ÷ Whole) × 100 = Percentage

Example:
If you got 18 points out of 20 on a test:
(18 ÷ 20) × 100 = 90%

So, you scored 90%.
Edited 2025-08-07 20:01 by Martin H.
'no comment
 
tenij000
Regular Member

Joined: 30/05/2025
Location: Netherlands
Posts: 51
Posted: 10:47am 07 Aug 2025
Copy link to clipboard 
Print this post

it is calc but cant calc % the + - * / all work
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10379
Posted: 11:12am 07 Aug 2025
Copy link to clipboard 
Print this post

% isn't a valid operator - see the manual. You have to do it by normal operators as per Martin's post
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8043
Posted: 11:19am 07 Aug 2025
Copy link to clipboard 
Print this post

There is no % maths function in MMBasic. The % symbol is used to denote an integer variable.

If you want a percentage function you will need to write it. e.g.

FUNCTION PC(percentage, number)
 PC = (percentage/number) * 100
END FUNCTION

a = PC(18,20)

This might be better than calculating percentages repeatedly in-line in some cases.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1621
Posted: 11:35am 07 Aug 2025
Copy link to clipboard 
Print this post

Possibly the "Mod" operator is meant.

Ragards
Michael
causality ≠ correlation ≠ coincidence
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 02:12pm 07 Aug 2025
Copy link to clipboard 
Print this post

And the other way round, if you want to know how much x% of a number is

part=(Whole/100)*Percentage

@twofingers MODulo determines the remainder of a division e.g. 7 MOD 4 =3
Edited 2025-08-08 00:23 by Martin H.
'no comment
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1621
Posted: 02:29pm 07 Aug 2025
Copy link to clipboard 
Print this post

Hi Martin,
  Martin H. said  ...
@twofingers MODulo determines the remainder of a division e.g. 7 MOD 4 =3

That's exactly how it is! And in other programming languages, '%' is the modulo operator. Could it be that the OP knows languages other than MMBasic?
I don't see that the OP asked about percentages.

MMBasic Manual  p24:
* / \ MOD
Multiplication, division, integer division and modulus (remainder)


Regards
Michael
causality ≠ correlation ≠ coincidence
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 02:41pm 07 Aug 2025
Copy link to clipboard 
Print this post

  twofingers said  in other programming languages, '%' is the modulo operator.
Could it be that the OP knows languages other than MMBasic?
I don't see that the OP asked about percentages.

MMBasic Manual  p24:
* / \ MOD
Multiplication, division, integer division and modulus (remainder)


Regards
Michael

Hi Michael,
of course you're right, I hadn't considered that
Edited 2025-08-08 00:42 by Martin H.
'no comment
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025