10
1
Sales taxes in the United States are complicated, to say the least. Generally, there's a state sales tax (there are a handful of states that do not collect a state sales tax), but there could also be a county sales tax, a school district sales tax, a municipal (city) sales tax, or a metropolitan area sales tax. There could even be different sales taxes in different parts of a city. For the purposes of this challenge, however, we're going to focus on just the state sales tax.
Given a U.S. dollar amount greater than zero (accurate to two decimal places) and a state (either the full name or the two-letter abbreviation, your choice, case doesn't matter), and using the below chart of sales tax percentages, output the corresponding state sales tax required to be collected for that particular sale, accurate and truncated to two decimal places. Please specify how your code handles rounding.
Edit: The abbreviation for Washington was listed incorrectly as WS instead of WA. Answers may use either abbreviation, since that was my goof.
State Abbr %
Alabama AL 4.00%
Alaska AK 0.00%
Arizona AZ 5.60%
Arkansas AR 6.50%
California CA 6.00%
Colorado CO 2.90%
Connecticut CT 6.35%
Delaware DE 0.00%
Florida FL 6.00%
Georgia GA 4.00%
Hawaii HI 4.00%
Idaho ID 6.00%
Illinois IL 6.25%
Indiana IN 7.00%
Iowa IA 6.00%
Kansas KS 6.50%
Kentucky KY 6.00%
Louisiana LA 5.00%
Maine ME 5.50%
Maryland MD 6.00%
Massachusetts MA 6.25%
Michigan MI 6.00%
Minnesota MN 6.875%
Mississippi MS 7.00%
Missouri MO 4.23%
Montana MT 0.00%
Nebraska NE 5.50%
Nevada NV 4.60%
New Hampshire NH 0.00%
New Jersey NJ 6.88%
New Mexico NM 5.13%
New York NY 4.00%
North Carolina NC 4.75%
North Dakota ND 5.00%
Ohio OH 5.75%
Oklahoma OK 4.50%
Oregon OR 0.00%
Pennsylvania PA 6.00%
Rhode Island RI 7.00%
South Carolina SC 6.00%
South Dakota SD 4.50%
Tennessee TN 7.00%
Texas TX 6.25%
Utah UT 4.70%
Vermont VT 6.00%
Virginia VA 4.30%
Washington WA 6.50%
West Virginia WV 6.00%
Wisconsin WI 5.00%
Wyoming WY 4.00%
Example for California at 6% state sales tax --
CA
1025.00
61.50
Example for Minnesota at 6.875% --
MN
123.45
8.49
14inb4 Mathematica builtin. – James – 2017-09-05T14:20:54.173
Minnesota MN 6.875%
- because .005% is, well, actually a lot. – Magic Octopus Urn – 2017-09-05T14:22:54.953@MagicOctopusUrn Also because Minnesota has to be different. The actual law is spelled out as a fraction "six and seven-eighths of a percent" (or somesuch) rather than a decimal, so that's why it's a weird number. – AdmBorkBork – 2017-09-05T14:25:53.513
Also why do OR, AK and MT have 0% sales tax, is that true?? – Magic Octopus Urn – 2017-09-05T14:26:59.540
@MagicOctopusUrn Yes, that's true. There are a handful of states that don't collect state sales tax on any purchase. There may still be county/city/etc. sales tax. – AdmBorkBork – 2017-09-05T14:27:50.773
1Ahhh... right... this isn't income tax. – Magic Octopus Urn – 2017-09-05T14:29:16.497
Do I have to truncate the values or is rounding okay? – JungHwan Min – 2017-09-05T14:33:44.547
@JungHwanMin Since we're dealing with currency, it doesn't make sense to have more than two decimal places. – AdmBorkBork – 2017-09-05T14:35:43.650
@AdmBorkBork I mean, does
0.495
have to become0.49
or can I round it up to0.50
? – JungHwan Min – 2017-09-05T14:36:57.247@JungHwanMin Up to you, just specify how you handle it. – AdmBorkBork – 2017-09-05T14:37:18.693
Does case matter for the input? – Shaggy – 2017-09-05T14:42:39.103
2@Shaggy No, case doesn't matter. – AdmBorkBork – 2017-09-05T14:43:17.463
2Pedantry: the state abbreviation for Washington is WA, not WS. – Michael Seifert – 2017-09-05T19:10:39.897
@MichaelSeifert Typo on my part. Thanks for pointing it out. – AdmBorkBork – 2017-09-05T19:16:20.860
Truncation would mean 0.495 -> 0.49. Rounding could be 0.50 or 0.49 depending on the rule. Removing truncation and just saying how you round to 2 decimal places is up to you would probably be clearer. – Batman – 2017-09-06T04:51:16.717