---
title: "Beräkning"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/169307-beräkning"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "devotion"
published: "2008-02-23T21:21:29.000Z"
updated: "2008-02-24T18:40:45.000Z"
replies: 6
views: 603
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/169307-beräkning"
---

# Beräkning

## #1 — devotion, 2008-02-23T21:21Z

Hej :)  

Jag har följande kod soim behöver modifieras:

```
if isNumeric(sDiscountPct) then
			fDiscountPct = cdbl(sDiscountPct)
		else
			fDiscountPct = 0
		end if
		
		if isNumeric(sExtraDiscountPct) then
			fExtraDiscountPct = cdbl(sExtraDiscountPct)
		else
			fExtraDiscountPct = 0
		end if
		
		fDiscountPct=fDiscountPct+fExtraDiscountPct
```

Beräkningsmodellen är dock felaktig...

nu gäller följande:

```
fDiscountPct = 1 -((1-fDiscountPct) * (1-fExtraDiscountPct))
```

Hur gör man för att ta hänsyn till om fDiscountPct eller fExtraDiscountPct är 0 ?

I nuvarande kod kommer ju et nollvärde på något av dssa värde inneböra att fDiscountPct blir 0

Mvh
Henrik

Permalänk: https://www.webforum.nu/p/169307

## #2 — Peter S, 2008-02-23T23:53Z

```
fDiscountPct = fDiscountPct * (1-fExtraDiscountPct) + fExtraDiscountPct
```

Permalänk: https://www.webforum.nu/p/2084649

## #3 — devotion, 2008-02-24T08:23Z

Hmmm.... Nu fattar jag ingenting... :)

Permalänk: https://www.webforum.nu/p/2084657

## #4 — Peter S, 2008-02-24T14:46Z

I

```
fDiscountPct = 1 -((1-fDiscountPct) * (1-fExtraDiscountPct))
```

...hur kan fDiscountPct bli 0 om fDiscountPct xor fExtraDiscountPct är 0? Den enda gången fDiscountPct blir 0 är ju om både fDiscountPct och fExtraDiscountPct är 0 samtidigt.

Permalänk: https://www.webforum.nu/p/2084709

## #5 — devotion, 2008-02-24T15:19Z

> **Peter S skrev:**
>
> I
>
> ```
> fDiscountPct = 1 -((1-fDiscountPct) * (1-fExtraDiscountPct))
> ```
>
> ...hur kan fDiscountPct bli 0 om fDiscountPct xor fExtraDiscountPct är 0? Den enda gången fDiscountPct blir 0 är ju om både fDiscountPct och fExtraDiscountPct är 0 samtidigt.

Hmmm.... Det har du rätt i...  :) 

Jag skrev detta inlägget efter en bättre middag, med lite alkoholhaltiga drycker... Så jag får skylla på det...

Då borde ju min beräkning fungera som det är tänkt...

Mvh
Henrik

Permalänk: https://www.webforum.nu/p/2084716

## #6 — Peter S, 2008-02-24T18:23Z

Japp! :)

Permalänk: https://www.webforum.nu/p/2084766

## #7 — devotion, 2008-02-24T18:40Z

Då fick det bli så här....

```
function GetDiscountPct(sNormalDiscountPct, sExtraDiscountPct)

	dim fDiscountPct, fNormalDiscountPct, fExtraDiscountPct
	
	if isNumeric(sNormalDiscountPct) then
		fNormalDiscountPct = cdbl(sNormalDiscountPct)/100
	else
		fNormalDiscountPct = 0
	end if
		
	if isNumeric(sExtraDiscountPct) then
		fExtraDiscountPct = cdbl(sExtraDiscountPct)/100
	else
		fExtraDiscountPct = 0
	end if

	fDiscountPct = 1 -((1-fNormalDiscountPct) * (1-fExtraDiscountPct))
	
	GetDiscountPct=fDiscountPct

End function
```

Mvh
Henrik

Permalänk: https://www.webforum.nu/p/2084772

---

Tråden på webben: https://www.webforum.nu/amne/asp/169307-beräkning
