kaasknak Posted January 11, 2013 Share Posted January 11, 2013 Hello, Currently I am encountering a problem with my script concerning decimal numbers. The problem is that the program rounds a number to a certain amount of decimals but I want more. Is there a way I can manipulate / change this? Here are the scripts. While 1 $aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.") ProgressOn ("Berekenen", "Vooruitgang", 0) If $aantal = 0 Then Exit Else $benadering = 0 For $noemer = 1 To $aantal ProgressSet( $noemer / $aantal * 100, Round ($noemer / $aantal * 100, 1) & "%") $temp = 1 / ($noemer ^ 2) $benadering = $benadering + $temp Next EndIf ProgressOff() $stap1 = $benadering * 6 $pi = Sqrt($stap1) If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & $pi) = 2 Then Exit EndIf WEnd $pi needs to be adapted $vraag=MsgBox(4, "Start", "Bereken phi?") If $vraag = 7 Then Exit EndIf $stap1 = Sqrt(5) $stap2 = 1 + $stap1 $stap3 = $stap2 / 2 $phi = $stap3 MsgBox(64, "uitkomst", "pi=" & $phi) $phi needs to be adapted While 1 $aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.") ProgressOn ("Berekenen", "Vooruitgang", 0) If $aantal = 0 Then Exit Else $benadering = 0 For $noemer = 0 To $aantal ProgressSet( $noemer / $aantal * 100, Round ($noemer / $aantal * 100, 1) & "%") $faculteit = faculteit($noemer) $temp = 1 / $faculteit $benadering = $benadering + $temp Next EndIf ProgressOff() $e=$benadering If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "e=" & $e) = 2 Then Exit EndIf WEnd Func faculteit($nummer) Local $n = 1.0 For $i = 1 to $nummer $n = $n*$i Next If $n = 0 Then SetError ( 1 ) Return 1 Else Return $n EndIf EndFunc $e needs to be adapted Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 11, 2013 Share Posted January 11, 2013 Found in helpfileThe decimalplaces parameter can be negative which allows you to round to the ones, tens, hundred, etc. place. Note that up to fifteen digits of a number are displayed, and note that decimalplaces will never pad a number with trailing zeros. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AZJIO Posted January 11, 2013 Share Posted January 11, 2013 kaasknak, I don't understand what you're doing, but slightly changed expandcollapse popupWhile 1 $aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.") If @error Or $aantal < 1 Then Exit If Not StringIsDigit($aantal) Then ContinueLoop ProgressOn("Berekenen", "Vooruitgang", 0) $benadering = 0 $tmp = 0 For $i = 0 To $aantal ; If Not Mod($i, 10) Then $tmpCur = Int($i / $aantal * 100) If $tmpCur > $tmp Then ProgressSet($tmpCur, $tmpCur & "%") $tmp = $tmpCur EndIf $faculteit = faculteit($i) $benadering += 1 / $faculteit Next ProgressOff() $e = $benadering If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "e=" & $e) = 2 Then Exit WEnd Func faculteit($nummer) Local $n = 1 For $i = 1 To $nummer $n *=$i Next If $n Then Return $n Else Return SetError(1, 0, 1) EndIf EndFunc ;==>faculteit My other projects or all Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now