Hola,
Mi duda es sobre como convertir el marcador que baja usando Gson de una API a double.
import com.google.gson.annotations.SerializedName;
public class Divisa {
@SerializedName("conversion_rate")
double tasaConversion;
Divisa ( double tasaConversion){
this.tasaConversion=tasaConversion;
System.out.println(tasaConversion);
}
}
Me arroja el marcador con @
"C:\Program Files\Java\jdk-17\bin\java.exe" "-javaagent:C:\Users\Maria Fernanda\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2024.2.3\lib\idea_rt.jar=54222:C:\Users\Maria Fernanda\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2024.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Maria Fernanda\IdeaProjects\ConversorDeMonedas\out\production\ConversorDeMonedas;C:\Users\Maria Fernanda\ORACLE JAVA backend\gson-2.10.1.jar" Main
Sea bienvenido al convertidor de divisas =) Elija el número de su selección a convertir:
"USD a ARS"
"ARS a USD"
"USD a BRL"
"BRL a USD"
"USD a COP"
"COP a USD"
4 BRL USD {"result":"success","documentation":"https://www.exchangerate-api.com/docs","terms_of_use":"https://www.exchangerate-api.com/terms","time_last_update_unix":1734912002,"time_last_update_utc":"Mon, 23 Dec 2024 00:00:02 +0000","time_next_update_unix":1734998402,"time_next_update_utc":"Tue, 24 Dec 2024 00:00:02 +0000","base_code":"BRL","target_code":"USD","conversion_rate":0.1644} {"result":"success","documentation":"https://www.exchangerate-api.com/docs","terms_of_use":"https://www.exchangerate-api.com/terms","time_last_update_unix":1734912002,"time_last_update_utc":"Mon, 23 Dec 2024 00:00:02 +0000","time_next_update_unix":1734998402,"time_next_update_utc":"Tue, 24 Dec 2024 00:00:02 +0000","base_code":"BRL","target_code":"USD","conversion_rate":0.1644} Divisa@14ec4505 Escriba el monto con centavos de BRL a convertir en USD : 100.10
y lógicamente no puedo usarlo para multiplicarlo para hacer la conversión:
System.out.println(response.body()); String json = response.body(); System.out.println(json); Gson gson = new Gson(); Divisa miDivisa = gson.fromJson(json, Divisa.class); System.out.println(miDivisa); Scanner lectureMonto = new Scanner(System.in); System.out.println(" Escriba el monto con centavos de " + MonedaOriginal + " a convertir en "+ MonedaConvertida+" : ");
MontoAConvertir = lectureMonto.nextInt();
MontoConvertido=MontoAConvertir*miDivisa.tasaConversion;
System.out.println("El monto convertido es de: " + MontoConvertido);
}
}
Gracias