Formats a float value to be as short as possible. Truncates float to 8 decimal places and trims extraneous trailing zeros and period to give API args the best possible chance of fitting within 2000 char URL length restrictions. For example: format_float(40) -> "40" for
(arg)
| 30 | |
| 31 | |
| 32 | def format_float(arg): |
| 33 | """Formats a float value to be as short as possible. |
| 34 | |
| 35 | Truncates float to 8 decimal places and trims extraneous |
| 36 | trailing zeros and period to give API args the best |
| 37 | possible chance of fitting within 2000 char URL length |
| 38 | restrictions. |
| 39 | |
| 40 | For example: |
| 41 | |
| 42 | format_float(40) -> "40" |
| 43 | format_float(40.0) -> "40" |
| 44 | format_float(40.1) -> "40.1" |
| 45 | format_float(40.001) -> "40.001" |
| 46 | format_float(40.0010) -> "40.001" |
| 47 | format_float(40.000000001) -> "40" |
| 48 | format_float(40.000000009) -> "40.00000001" |
| 49 | |
| 50 | :param arg: The lat or lng float. |
| 51 | :type arg: float |
| 52 | |
| 53 | :rtype: string |
| 54 | """ |
| 55 | return ("%.8f" % float(arg)).rstrip("0").rstrip(".") |
| 56 | |
| 57 | |
| 58 | def latlng(arg): |