9 Replies - 419 Views - Last Post: 13 December 2019 - 06:57 AM Rate Topic: -----

#1 membernew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-December 19

Convert sin, cos,tan in degree

Posted 11 December 2019 - 01:27 PM

I tried to convert into degrees and it doesn't work for anything.
This only works for sin 90, and when i say sin 180 it doesn't work
Label3.Text = Math.Sin(txtDisplay.Text * (Math.PI / 180))
Is This A Good Question/Topic? 0
  • +

Replies To: Convert sin, cos,tan in degree

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15477
  • View blog
  • Posts: 62,007
  • Joined: 12-June 08

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 01:29 PM

First - "txtDisplay.Text" should be converted to a number. .TEXT is a STRING not an number.

If you look at the documentation you'll see the input parameter is a double.
https://docs.microso...etframework-4.8

It would be in your best interest to turn on explicit and strict.

Tools -> options -> project & solutions -> vbdefaults

Option explicit -> on
option strict -> on.
Was This Post Helpful? 0
  • +
  • -

#3 membernew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-December 19

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 01:46 PM

I tried this and it's not working, I don't think this is good
Dim sinus As Double
        sinus = Double.Parse(txtDisplay.Text)
        sinus = Math.Sin(sinus * (Math.PI / 180))
        txtDisplay.Text = System.Convert.ToString(sinus)

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15477
  • View blog
  • Posts: 62,007
  • Joined: 12-June 08

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 01:50 PM

Mkay.. so what is "txtDisplay" supposed to contain? Degrees or radians?
Was This Post Helpful? 0
  • +
  • -

#5 membernew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-December 19

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 01:54 PM

Well I'm trying to make a calculator, so txtDisplay is a TextBox where I put a number, then hit the sin button and the answer to be in degrees.
For example, my problem is that when I introduce 90 and hit sin it gives me the output in radians and I need it in degrees, like sin 90 to be 1
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15477
  • View blog
  • Posts: 62,007
  • Joined: 12-June 08

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 02:02 PM

Look at your formula. Does that look right?

sinus * (Math.PI / 180)


Doing the division first then the multiplication? Shouldn't that be the multiplication first then all of that divided by 180?

https://www.wikihow....rees-to-Radians

Order of operations matters.
Was This Post Helpful? 0
  • +
  • -

#7 membernew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-December 19

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 02:08 PM

OH, right!
But then still does not work, and I just don't understand why because i converted it to calculate in degrees
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15477
  • View blog
  • Posts: 62,007
  • Joined: 12-June 08

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 02:15 PM

If your input is in degrees, and you fixed you formula, then it should work.

sin 90 degrees -> 1
sin 45 degrees -> 0.707106781186547
sin 87 degrees -> 0.998629534754574

Was This Post Helpful? 0
  • +
  • -

#9 membernew   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-December 19

Re: Convert sin, cos,tan in degree

Posted 11 December 2019 - 02:22 PM

For sin pi gives me 5.48311355616075E+19 and it should be 0

Oh sorry, the input it's in radians
Was This Post Helpful? 0
  • +
  • -

#10 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 124
  • View blog
  • Posts: 686
  • Joined: 01-October 08

Re: Convert sin, cos,tan in degree

Posted 13 December 2019 - 06:57 AM

Look at the remarks here
https://docs.microso...lp/sin-function
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1