# String to Float conversion

**URL:** <https://community.hubspot.com/t/string-to-float-conversion/124765>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [January 25, 2025, 12:56pm UTC](https://community.hubspot.com/t/string-to-float-conversion/124765 "2025-01-25T12:56:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSandbox](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fsandbox/32/56602_2.png) [@FSandbox](https://community.hubspot.com/u/FSandbox)\
**Post date:** [January 25, 2025, 12:56pm UTC](https://community.hubspot.com/t/string-to-float-conversion/124765/1 "2025-01-25T12:56:47Z")

</div>

Hi,

I am facing problem in string to float conversion in dutch language.

I need to get values from URL and convert to float because further calculation.

/nl-be/kantoren?lat=50.864860&lon=2.887811&location=8900

IN URL Lat = (String: 50.864860)  
IN URL Lon = (String: 2.887811)  
AFTER FLOAT Lat = (Float: 5.086486E7)  
AFTER FLOAT Lon = (Float: 2887811.0)

After conversion values are not correct.

But in english language its working fine.

/en/kantoren?lat=50.864860&lon=2.887811&location=8900  
IN URL Lat = (String: 50.864860)  
IN URL Lon = (String: 2.887811)  
AFTER FLOAT Lat = (Float: 50.86486)  
AFTER FLOAT Lon = (Float: 2.887811)

I am using |float filter for coversion and get value from URL using request.query\_dict.

Thanks.

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [January 26, 2025, 1:13am UTC](https://community.hubspot.com/t/string-to-float-conversion/124765/2 "2025-01-26T01:13:15Z")

</div>

Hello! @FSandbox

### Why It’s Happening:

- In English, 50.864860 is treated as 50 point 864860.
- In Dutch, 50.864860 is interpreted differently (it might not parse correctly because . could be considered a thousands separator, leading to 50.864860 being read as 50864860).

## **Possible Solution:**

1. Set locale to English temporarily
2. Get values
3. Set locale back to Dutch

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/0/707280cae4a04999540e3e920e717c53f28d0a56.png)Was I able to help answer your question? Help the community by **marking it as a solution.**

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [January 29, 2025, 7:06pm UTC](https://community.hubspot.com/t/string-to-float-conversion/124765/3 "2025-01-29T19:06:03Z")

</div>

Hey @FSandbox 👋 How about something like this? My function assumes you’re _only_ dealing with US or Dutch locales.

```lia-code-sample
function safeFloatParse(value, locale = 'en-US') {
 // Validate locale
 if (!['en-US', 'nl-BE'].includes(locale)) {
 throw new Error(`Unsupported locale: ${locale}`);
 }

 if (typeof value !== 'string') {
 value = String(value);
 }

 // Define separators
 const separators = {
 'nl-BE': { thousand: '.', decimal: ',' },
 'en-US': { thousand: ',', decimal: '.' }
 };

 const { thousand, decimal } = separators[locale];

 // Remove separators and normalize
 const normalizedValue = value
 .trim() // Handle whitespace
 .replace(new RegExp(`\\${thousand}`, 'g'), '')
 .replace(decimal, '.');

 // Parse
 const parsedValue = parseFloat(normalizedValue);

 // Validate
 if (isNaN(parsedValue)) {
 throw new Error(`Unable to parse value: ${value}`);
 }

 return parsedValue;
}

```

I tried to:

- use explicit locale validation
- trim whitespace
- use an Object for readability
- include error handling

I hope this helps get you moving forward! — Jaycee
