Temperatura Celciusz na farenhait - dobry wzrór nie działa

0

Mam zrobioną małą aplikacje - zmiana temp z F na C i odwrotnie
Zmiana z F na C działa dobrze, ale znów z C na F nie.

Wzór mam dobry. Kod wygląda tak:

<WebMethod()> _
    Public Function CelciusNaFahrenheit _
    (ByVal Celcius As Double) As Double
        Return ((Celcius * 9 / 5) + 32)
    End Function

100 F = 37,7777777777778 C

ale

37,7777777777778 C = 3,20987701416016 F

Czy ten wzór na pewno jest ok?

0

No jak nie działa, jak działa podane przez Ciebie wzór.

Jeśli F = 9/5C + 32, to C = 5/9 (F-32)

Jeśli C = 37 , to F = 98,6
Jeśli F = 98,6 to C = 37

Sprawdź co tam zaimplementowałeś :)

0

Spróbuj

Return ((Celcius * 9.0 / 5.0) + 32.0)
0

Niestety to samo

Otóż coś musi być źle chyba po stronie formularza.
Bo aplikacja jest robiona tak, żeby dało się z niej korzystać po stronie klienta(zrobiony formularz również w vb)

Jeśli chodzi o uruchomienie tego po stronie 'serwera' to normalnie wynik wyświetla się dobry tylko w kodzie xml
Zrobiłem do tego formularz w tabeli żeby zamieniał te temperatury i tutaj niestety wynik podaje błędny

Podam może cały kod tych aplikacji.

Najpierw od strony 'serwer' :

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function FahrenheitNaCelcius _
    (ByVal Fahrenheit As Double) As Double
        Return ((Fahrenheit - 32) * 5) / 9
    End Function



    <WebMethod()> _
    Public Function CelciusNaFahrenheit _
    (ByVal Celcius As Double) As Double
        Return ((Celcius * 9.0 / 5.0) + 32.0)
    End Function

End Class

I poniżej od strony 'klient'
Może tu coś jest źle?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            height: 287px;
        }
        .style2
        {
            text-align: center;
        }
        .style3
        {
        }
        .style4
        {
            width: 224px;
        }
        .style5
        {
            width: 278px;
        }
        .style6
        {
            width: 269px;
            height: 26px;
        }
        .style7
        {
            width: 278px;
            height: 26px;
        }
        .style8
        {
            width: 224px;
            height: 26px;
        }
        .style9
        {
            height: 26px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td class="style2" colspan="4">
                <strong>Konwersja temperatur w dwóch skalach: Farenheita i Celciusza<br />
                </strong>
            </td>
        </tr>
        <tr>
            <td class="style3">
                Temperatura dla Farenheita:</td>
            <td class="style5">
                <asp:TextBox ID="txtF" runat="server"></asp:TextBox>
            </td>
            <td class="style4">
                Temperatura dla Celciusza</td>
            <td>
                <asp:TextBox ID="txtC" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style3">
                &nbsp;</td>
            <td class="style5">
                &nbsp;</td>
            <td class="style4">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                &nbsp;</td>
            <td class="style5">
                <asp:Button ID="cmdFnaC" runat="server" Text="Farenheit na Celciusz" />
            </td>
            <td class="style4">
                &nbsp;</td>
            <td>
                <asp:Button ID="cmdCnaF" runat="server" Text="Celciusz na Farenheit" />
            </td>
        </tr>
        <tr>
            <td class="style3">
                &nbsp;</td>
            <td class="style5">
                &nbsp;</td>
            <td class="style4">
                <asp:Button ID="cmdResetuj" runat="server" Text="Resetuj" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                &nbsp;</td>
            <td class="style5">
                &nbsp;</td>
            <td class="style4">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                Temperatura po konwersji w skali<br />
                Celciusza</td>
            <td class="style5">
                <asp:TextBox ID="outC" runat="server" ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style4">
                Temperatura po konwersji w skali<br />
                Farenheita</td>
            <td>
                <asp:TextBox ID="outF" runat="server" ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style3">
                &nbsp;</td>
            <td class="style5">
                &nbsp;</td>
            <td class="style4">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style6">
            </td>
            <td class="style7">
            </td>
            <td class="style8">
            </td>
            <td class="style9">
            </td>
        </tr>
        <tr>
            <td class="style3" colspan="4">
                &nbsp;</td>
        </tr>
    </table>
    <div>
    
    </div>
    </form>
</body>
</html>

1 użytkowników online, w tym zalogowanych: 0, gości: 1