scriptsharp
scriptsharp copied to clipboard
String Replace Bug - 0.8
The following C# code produces javascript which is broken:
The stringvalue.replace is swapped for stringvalue.ss.replaceString ss is undefined
public static string NumberToString(Number value)
{
if (value >= 0)
{
if (value < 10)
{
value = Round(value, 2);
return value.ToString().Replace(".0", "");
}
if (value < 1000)
{
value = Round(value, 1);
return value.ToString().Replace(".0", "");
}
if (value < 1000000)
return Round((value / 1000), 1).ToString().Replace(".0", "") + "K";
return Round((value / 1000000), 1).ToString() + "M";
}
return "-" + NumberToString(value * -1);
}
Here is the outputted javascript for the above c# scriptsharp
SLC$Common$NumberHelpers.numberToString = function(value) {
if (value >= 0) {
if (value < 10) {
value = SLC$Common$NumberHelpers.round(value, 2);
return value.toString().ss.replaceString('.0', '');
}
if (value < 1000) {
value = SLC$Common$NumberHelpers.round(value, 1);
return value.toString().ss.replaceString('.0', '');
}
if (value < 1000000) {
return SLC$Common$NumberHelpers.round((value / 1000), 1).toString().ss.replaceString('.0', '') + 'K';
}
return SLC$Common$NumberHelpers.round((value / 1000000), 1).toString() + 'M';
}
return '-' + SLC$Common$NumberHelpers.numberToString(value * -1);
}
The metadata on Replace method on String is incorrect - should have been [ScriptAlias] and not [ScriptName]. Fix is checked in ... will include in the next 0.8 preview build.