![]() |
Forum Index : Microcontroller and PC projects : howto calc whit the %
Author | Message | ||||
tenij000 Regular Member ![]() Joined: 30/05/2025 Location: NetherlandsPosts: 51 |
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: GermanyPosts: 1270 |
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: NetherlandsPosts: 51 |
it is calc but cant calc % the + - * / all work |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10379 |
% 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 KingdomPosts: 8043 |
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: GermanyPosts: 1621 |
Possibly the "Mod" operator is meant. Ragards Michael causality ≠correlation ≠coincidence |
||||
Martin H.![]() Guru ![]() Joined: 04/06/2022 Location: GermanyPosts: 1270 |
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: GermanyPosts: 1621 |
Hi Martin, 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: GermanyPosts: 1270 |
Hi Michael, of course you're right, I hadn't considered that Edited 2025-08-08 00:42 by Martin H. 'no comment |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |