2
Hello,
I created an API that receives two parameters from another project (requirement of college work), is the calculation of the BMI, so it receives weight and height and makes the calculation, until then quiet.
---- API
namespace API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class IMCController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get(double peso, double altura)
{
string stg = "";
//os parametros devem ser passados pela url.
// EX: api/ExercicioAPI?peso=75&altura=1.69
if (peso != 0 && altura != 0)
{
double valor = peso / (altura * altura);
stg = valor.ToString();
}
else
{
stg = "0";
}
string json = "{ imc: " + double.Parse(stg).ToString("0.00") + "}";
return json;
}
}
}
---- In the project controller, I get this:
public double getImc(double peso, double altura)
{
double imc = 0;
using (var client = new WebClient())
{
//double teste = 1.59;
string url = "http://localhost:61822/api/IMC?peso=" + 59 + "&altura=" + altura;
string json = client.DownloadString(url);
imc = Convert.ToDouble(new string(json.Where(char.IsDigit).ToArray()));
}
return imc;
}
Every time the url string takes the value with comma ex. 1.59, even coming as string, int, double.
Even when I tested with the variable "test" there, it passed the variable url 1.59
I tried to pass as string the height in the project API and controller and before the calculation convert to double, but also received with comma, instead of dot.
Any idea what that problem is or how to fix it? I searched and found nothing, I’m using the visual studio in English, I was thinking that it could be something of the system of Brazil use the comma in decimal and be converting in the browser, but I could not find how to fix.