# Powershell .net [math]::tan not giving the expected value

• ### Question

• Powershell working with .net [math]::tan

Using the built in calculator for win10

I enter

1.8084375 Tan

It returns

.03157367431985105976535923938818

But in powershell

[decimal][math]::tan(1.8084375)

Returns

-4.12851144057728

The calculator is giving me the answer I am looking for how do I make powershell do the same? i am thinking the calculator is working in degrees and the .net in something else?

Thx

bob

Monday, June 12, 2017 8:57 PM

• \$radians = \$degrees * 0.0174533

OR

\$degrees * ([math]::PI/180)

\_(ツ)_/

• Edited by Monday, June 12, 2017 10:35 PM
• Marked as answer by Tuesday, June 13, 2017 12:38 AM
Monday, June 12, 2017 10:31 PM

### All replies

• PowerShell is correct.

\_(ツ)_/

Monday, June 12, 2017 9:18 PM
• ok so [math]Tan is expecting radians with no way to tell it to use degrees... so i need to convert degrees to radians.

[decimal]\$vAngleInDegrees=(\$vAngle/2*.05625)
\$vSubtendedDistance=((1/([decimal][math]::Tan((\$vAngleInDegrees / 180 * [math]::PI))))*\$vBase/2)
\$vSubtendedDistance

a bit clunky but seems to work, any suggestions how to cut down on the rounding, it shows much more precision in the end result than the intermediate steps would indicate?

thx

bob

Monday, June 12, 2017 10:23 PM
• \$radians = \$degrees * 0.0174533

OR

\$degrees * ([math]::PI/180)

\_(ツ)_/

• Edited by Monday, June 12, 2017 10:35 PM
• Marked as answer by Tuesday, June 13, 2017 12:38 AM
Monday, June 12, 2017 10:31 PM