7 Replies - 1001 Views - Last Post: 18 May 2010 - 06:09 PM Rate Topic: -----

#1 Stuart444  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 23-March 07

Need help with VAT/Sales Tax...

Posted 16 May 2010 - 08:03 AM

For one of my classes, we need to make a new ASP.NET website using another site we did as a basis (We were using one of the wrox books to learn ASP.NET and made the site during it).

Now I'm trying to set the Sales Tax/VAT (It was called Sales Tax in the book but we're to call it VAT for this website now). With sales tax in the web.config file, it was done using:

	
<appSettings>
	<add key="SalesTax" value="0.08"/>
</appSettings>



now I modified it a few times to try and get the VAT to work (VAT in the UK is 17.05% just incase anyone doesn't know)

	
<appSettings>
	<add key="SalesTax" value="17.05"/>
</appSettings>



I first tried it like that and the result when I tested it on the site was:

Quote

VAT (1705%)


which is treated as a whole number instead of a decimal (as in, it's not treated as 17.05)

I'm quite confused since as soon as I turn it back to 0.08, it comes out as 8% but when I try 17.05 it comes out as 1705%. I'm not sure what other code I can put here to help since I'm assuming the problem lies with the code I put above.

Can anyone help with this problem?

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with VAT/Sales Tax...

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Need help with VAT/Sales Tax...

Posted 16 May 2010 - 10:36 AM

Percentages written in decimal form are less than 1.0 and greater than 0. You divide the whole percentage 17.05% by 100 to derive the decimal equivalent of the percentage.

8 / 100 = .08

17.05 / 100 = .1705

<appSettings>
        <add key="SalesTax" value=".1705"/>
</appSettings>

Was This Post Helpful? 1
  • +
  • -

#3 Stuart444  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 23-March 07

Re: Need help with VAT/Sales Tax...

Posted 17 May 2010 - 03:21 AM

A bit of a late response but...

Thanks alot for that. it worked... in a way. What I mean is it doesn't act as 1705% anymore or anything like that but now it rounds it up to 17% instead of 17.05. (btw, I made a mistake in the first post, I think VAT is actualy 17.50 since its 17.5 and I assumed originally that meant 05 for some reason. Even when I change it, it instead rounds it up to 18% instead of just 17.5%)

I'm not sure now if this is a problem inside my web.config file or one of my other files. Anyone have any ideas as to what may be going wrong here?
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Need help with VAT/Sales Tax...

Posted 17 May 2010 - 05:20 AM

Are you reading the value into an integer variable? Can we see the code where you are getting that value from the web.config?
Was This Post Helpful? 0
  • +
  • -

#5 Stuart444  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 23-March 07

Re: Need help with VAT/Sales Tax...

Posted 17 May 2010 - 05:31 AM

View Posteclipsed4utoo, on 17 May 2010 - 11:20 AM, said:

Are you reading the value into an integer variable? Can we see the code where you are getting that value from the web.config?


I'll just paste any code I see that might effect it:

_salesTaxPercent = Convert.ToDecimal(ConfigurationManager.AppSettings("SalesTax"))


    Public ReadOnly Property SalesTaxPercent() As Decimal
        Get
            Return _salesTaxPercent
        End Get
    End Property


That's everything that uses _salesTaxPercent

and this is everything else that I is to do with Sales Tax (I think)

    Public ReadOnly Property SalesTax() As Decimal
        Get
            Return (SubTotal + DeliveryCharge) * SalesTaxPercent
        End Get
    End Property


    Public ReadOnly Property Total() As Decimal
        Get
            Return SubTotal + DeliveryCharge + SalesTax
        End Get
    End Property


I think that is everything to do with SalesTax

edit: OH and the _salesTaxPercent is set as a decimal variable

Private _salesTaxPercent As Decimal


just incase thats important

This post has been edited by Stuart444: 17 May 2010 - 05:33 AM

Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Need help with VAT/Sales Tax...

Posted 17 May 2010 - 05:57 AM

That looks fine.

And you are saying that when you read "17.50"(or "17.05) from the config file, it reads as 17?
Was This Post Helpful? 0
  • +
  • -

#7 Stuart444  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 23-March 07

Re: Need help with VAT/Sales Tax...

Posted 17 May 2010 - 06:02 AM

View Posteclipsed4utoo, on 17 May 2010 - 11:57 AM, said:

That looks fine.

And you are saying that when you read "17.50"(or "17.05) from the config file, it reads as 17?


yes, 17.05 reads as 17% (which shows it rounded down) and 17.50 is shown as 18% (which shows it rounded up).

What confuses me even more is the original version which used 0.08 didn't round up to 1.00 or anything like that

edit: if I can't get any help with this, I'll just go in tomorrow and ask my lecturer. It's to be in tomorrow but that usually means the end of the day tomorrow. Until then I can just do everything else that I am able to do until then.

Thanks for trying to help though guys :) appreciate it

This post has been edited by Stuart444: 17 May 2010 - 06:11 AM

Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Need help with VAT/Sales Tax...

Posted 18 May 2010 - 06:09 PM

I have to agree with eclipsed4utoo. So far what you've shown would not have caused any rounding to occur.

When you put a break on the line that gets the value from the web.config and debug your web application, what is the value that is initially stored in _salesTaxPercent? Is it 18%?

_salesTaxPercent = Convert.ToDecimal(ConfigurationManager.AppSettings("SalesTax"))


Would it be possible to see more of your code?

Perhaps there is something you are overlooking that could be causing the issue. It never hurts to have a second pair of eyes look it over.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1