Bonjour,
J'aimerais calculer un nombre qui aurait impérativement 3 chiffres après la virgule ; Exemple : 0.035 ou 0.000)
Comment s'y prendre ?
J'aimerais aussi savoir comment savoir si une variable contient un nombre négatif ?
D'avance, merci
_______________________________________________________________________________________________
Hello,
I would like to calculate a number that would have absolutely three decimal places; Example: 0.035 or 0.000)
How?
I would also like to know how to know if a variable contains a negative number?
In advance, thank you
Calculer à 3 chiffres après la virgule / Calculate to 3 dec.
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
NY152 wrote:I would like to calculate a number that would have absolutely three decimal places; Example: 0.035 or 0.000)
I would also like to know how to know if a variable contains a negative number?
Code: Select all
a.f=-0.005
b.f=0.040
c.f=a+b
Debug StrF(c,3)
If a<0 : Debug "'a' is negative" : EndIf
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
Mais si on test a < 0.xxx ca ne fonctionne pas. J'aurais aimé pouvoir le faire.
________________________________________
But if you test with a < 0.xxx it does not work. I wish I could do it.
________________________________________
But if you test with a < 0.xxx it does not work. I wish I could do it.
.:NY152:.
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
Code: Select all
a.f=-0.005
If a<0.222
Debug "'a' is negative"
EndIf
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
Yes it does. For a number to be negative, it has to be < 0. Show me your code so I can see what you're doing wrong.NY152 wrote:if you test with a < 0.xxx it does not work

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
Code: Select all
cowbell.d = -0.123456 ; You can't limit the decimal places for the actual stored number
Debug cowbell
Debug StrD(cowbell, 3) ; But you can control how many decimal places to display
cowbell=ValD(StrD(cowbell, 3)) ; Or truncate some if you wish
Debug cowbell
If cowbell < 0 ; Test for negative
Debug "NEED MORE COWBELL!!" ; Should want more cowbell
EndIf
Last edited by netmaestro on Wed Feb 25, 2015 5:30 pm, edited 1 time in total.
BERESHEIT
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
You could use an integer type and multiply everything by 1000 and divide by 1000 when presenting a result.netmaestro wrote:You can't limit the decimal places for the actual stored number
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
Sorry I was unclear. You can't limit the number of places but there's a couple of ways you can remove unwanted ones.You could use an integer type and multiply everything by 1000 and divide by 1000 when presenting a result.
BERESHEIT
Re: Calculer à 3 chiffres après la virgule / Calculate to 3
My idea is to calculate a bitrate automatically.
Is incremented by 1 as bitrate value quality 'Bit / Pixel' is not reached. I aim 0.076.
My essay:
Is incremented by 1 as bitrate value quality 'Bit / Pixel' is not reached. I aim 0.076.
My essay:
Code: Select all
EnableExplicit
Global sLargeur.f
Global sHauteur.f
Global sIPS.f
Global Largeur.s
Global Hauteur.s
Global IPS.s
Global BitPerPixel.f
Global Bitrate.f = 100
Global pause.s
OpenConsole("Bit/Pixel Calculator")
Print("Largeur de la vidéo : ")
Largeur = Input()
Print("Hauteur de la vidéo : ")
Hauteur = Input()
Print("Image par seconde de la vidéo : ")
IPS = Input()
sLargeur=ValF(Largeur)
shauteur=ValF(Hauteur)
sIPS=ValF(IPS)
BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
Repeat
If BitPerPixel < 0.076
Bitrate=Bitrate+1
BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
PrintN("+Bitrate: " + BitRate + " Bit/Pixel: " + BitPerPixel); For Info
ElseIf BitPerPixel > 0.076
Bitrate=Bitrate-1
BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
PrintN("+Bitrate: " + BitRate + " Bit/Pixel: " + BitPerPixel)
EndIf
Until BitPerPixel=0.076
Print("Bitrate: " +BitRate + " Bit/Pixel: " + BitPerPixel)
pause=Input()
CloseConsole()
.:NY152:.