Function in jQuery Ajax does not return a value

convertreal function (value) {

var currency = 0;
var value = value;
var valueconverted = 0;

$ .ajax ({
url: https: //free.currencyconverterapi.com/api/v6/convert? q = BRL_CNY & compact = ultra & apiKey = 873041c527593ec7e31e,
dataType: & quot; jsonp & # 39;
success: function (data) {
currency = data.BRL_CNY;
console.log (currency);
converted value = (currency * value);

function format (v) {
return parseFloat (v) .toLocaleString ("en-BR", {style: "currency", currency: "BRL"});
}
//document.write(format(convertedvalue));

value = format (converted value);


}

})
return value;
}

var testvalor = convertreal (400);
$ ("#real value"). html (testvalue);


The real value is: BRL