Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Funktion Runden geht nicht zu 100 Prozent


  • Please log in to reply
20 replies to this topic
just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
RoundByResult(Result) {
   If (Round(Result) = Result)
      Return, Round(Result)
   Else If Result between -999 And 999
      Return, Round(Result, 4)
   Else
      Return, Round(Result, 2)
}

Prefer ahkscript.org for the time being.


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
edit... warte kurzer denkfehler
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

strobo
  • Members
  • 359 posts
  • Last active: Mar 10 2015 08:13 PM
  • Joined: 19 Jun 2012

Was funzt da nicht?
vllt hast du /1 bei v/1 übersehen. k.a.
 


Regards,
Babba

nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012
RoundByResult(result)
{
RegExMatch(Zahl,"\d+.?(\d*)",Nachkomma)
Nachkomma:=RegExReplace(Nachkomma1,"0*$")
	if !Nachkomma
		return, result
	else
	{
		If (((Zahl**2)**05)<1000)
			return, Round((result), 4)
		else
			return, Round((result), 2)
	}
}

Visit the new forum ahkscript.org.

http://ahkscript.org


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
hast du's auch mal getestet?
 
MsgBox, % RoundByResult(20 * 20)
MsgBox, % RoundByResult(20 / 20)
MsgBox, % RoundByResult(10 / 20)
MsgBox, % RoundByResult(74.1353 * 93.376)
MsgBox, % RoundByResult(-74.1353 * 93.376)
Das ist mein Versuch wie es bis jetzt am besten Funktioniert
RoundByResult(result)
{
	if result is Integer
	{
		return, result
	}
	else
	{
		if result between -999 and 999
		{
			res1 := % Round((result), 4)
			res2 := % RegExReplace(res1, "\.?0+$")
			return, res2
		}
		else
		{
			res1 := % Round((result), 2)
			res2 := % RegExReplace(res1, "\.?0+$")
			return, res2
		}
	}
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Sorry mein Fehler

RoundByResult(result)
{
RegExMatch(result,"-?\d+\.?(\d*)",Nachkomma)
Nachkomma:=RegExReplace(Nachkomma1,"0*$")
	msgbox % Nachkomma
	if !Nachkomma
		return, result
	else
	{
		If (((result**2)**0.5)<1000)
			return, Round(result, 4)
		else
			return, Round((result), 2)
	}
}

EDIT: Ich hab es nochmal verändert damit negative Zahlen auch unterstützt werden.


Visit the new forum ahkscript.org.

http://ahkscript.org