Home › Forums › General discussion › Decimal separator in currency field (not a comma)
- This topic has 7 replies, 2 voices, and was last updated 6 years ago by Ayanda Makhathini.
-
AuthorPosts
-
-
December 5, 2018 at 13:52 #22957
Hi there
I have a form which does simple calculations but the issue I’m having is with the currency field not having comma’s instead of fullstops(dots). I’m using a CCDD (Cascading drop down) to select the product which selects the price field from the lookup list which is of type currency but returns it in the current list as single line ,I then have a h_price field that is of type currency which is set with a dot in it . There are numbers in the fields but the form wont save unless i change dots to commas. I’m also using (calc:) in rules to set the correct values, Can someone point me in the right direction for the solution of this
Attachments:
-
December 5, 2018 at 21:06 #22960
The problem is that the field value pulled from the db by the query is returned as a number with dot as decimal separator. If you need to use this number in a currency or number fields and your locale number format expects a comma you must replace the dot with a comma. How are you setting the value in the hidden fields?
Alexander
-
December 6, 2018 at 07:42 #22965
hi Alex
I’m using the the CCDD to select the product from another list which selects the price in the lookup list which is a currency field. I’m using a DFFS rule in the current list to set the h_price field which is a currency field. I’m trying to use a Custom JS function to change decimals to comma’s when the field changes but my syntax is not that great
-
December 6, 2018 at 15:05 #22968
Hi Alex
I also noticed that my calculations are not rounding off to 2 decimal places. I have the value 6118.43 pulling in as 6118.425 on the form. When I calculate (value) x (quantity) = (6118.425 x 2 = 12236850) . After that I calculate VAT and Total excluding VAT (VAT=15%). Amount including VAT is 14072.37 but i get 14072377.5 which will save as 14 Million if i replace comma. Would adding a custom function to round off solve the issue or is there a shorter way around it. I managed to remove decimals and replace them with commas but this wont if I’m rounding off to wrong decimal place. I currently have my calculations set in the DFFS rules. Amount exluding VAT = calc:{h_price}*{Quantity} , Total including VAT – calc:{Amount}*0.15+{Amount} . I think my main issue is to round off now
regards
Attachments:
-
December 6, 2018 at 18:54 #22973
You have better control is you use a custom function to do the calculation. Here is an example you can call from a rule (in the Run these functions field):
function doMyCalculation(){ var a = getFieldValue("FieldInternalName1"); var b = getFieldValue("FieldInternalName2"); // Do the calculation var c = a * b; // Truncate to two decimals var d = c.toFixed(2); // Replace . with , var e = String(d).replace(".",","); // Write to another field setFieldValue("TargetFieldInternalName",e); }
Alexander
-
December 7, 2018 at 08:37 #22991
Hi Alex
Thank you for the function it works.The calculation,rounding off and replace comma works well but i noticed that I’m losing couple cents if I dont round off the value of the item which isn’t rounded off when i get it from look up list, I’m using the function below to get the value(hprice) and try using the toFixed(2) but i get a error. Not sure yet but also working on it.
function convertprice()
{
var hPrice = getFieldValue(“h_price”);var priceValueFixed = hPrice.toFixed(2);
setFieldValue(“h_price”,priceValueFixed);
}
Regards
Attachments:
-
December 7, 2018 at 16:15 #22996
The function toFixed only works with numbers and the value you get from getFieldValue is string and not number. You can convert it like this:
function convertprice(){ var hPrice = getFieldValue("h_price"); if(hPrice !== ""){ var priceValueFixed = Number(hPrice).toFixed(2); setFieldValue("h_price",priceValueFixed); } }
You might want to change the toFixed method with Math.round like this:
var priceValueFixed = Math.round(Number(hPrice) * 100) / 100;
Alexander
-
December 13, 2018 at 10:25 #23112
Hi Alex
I used var price = parseFloat(getFieldValue(“Price”)).toFixed(2); to convert to number then i did calculations then converted to string with comma, You helped me alot. Thank you very much
Regards
Mak
-
-
AuthorPosts
- You must be logged in to reply to this topic.