Skip to content
Fix Code Error

Converting double to string

March 13, 2021 by Code Error
Posted By: Anonymous

I am not sure it is me or what but I am having a problem converting a double to string.

here is my code:

double total = 44;
String total2 = Double.toString(total);

Am i doing something wrong or am i missing a step here.

I get error NumberFormatException when trying to convert this.

totalCost.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
    try {
      double priceG = Double.parseDouble(priceGal.getText().toString());
      double valG = Double.parseDouble(volGal.toString());
      double total = priceG * valG;
      String tot = new Double(total).toString();
      totalCost.setText(tot);
    } catch(Exception e) {
      Log.e("text", e.toString());
    }

    return false;
  }         
});

I am trying to do this in an onTouchListener. Ill post more code, basically when the user touches the edittext box i want the information to calculate a fill the edittext box.

Solution

double total = 44;
String total2 = String.valueOf(total);

This will convert double to String

Answered By: Anonymous

Related Articles

  • How to aggregate values from a list and display in…
  • How to count input whenever the user input something…
  • Ember 2, filter relationship models (hasMany,…
  • Android Image View Pinch Zooming
  • Google Maps Android API v2 - Interactive InfoWindow…
  • Draw in Canvas by finger, Android
  • HorizontalScrollView within ScrollView Touch Handling
  • Vue.JS & Spring Boot - Redirect to homepage on 404
  • How to filter a RecyclerView with a SearchView
  • Maven2: Missing artifact but jars are in place
  • Fling gesture detection on grid layout
  • Item position in RecyclerView only changing when…
  • How can I give an imageview click effect like a…
  • How to use View.OnTouchListener instead of onClick
  • Problems with local variable scope. How to solve it?
  • Android: How to handle right to left swipe gestures
  • android: move a view on touch move (ACTION_MOVE)
  • Android + Pair devices via bluetooth programmatically
  • How do the PHP equality (== double equals) and…
  • Throw HttpResponseException or return…
  • Javax.net.ssl.SSLHandshakeException:…
  • Appropriateness of method for spinner
  • How can I throw CHECKED exceptions from inside Java…
  • Vuejs total variable for cart returning NaN
  • Problems Installing CRA & NextJS from NPM…
  • How to implement HorizontalScrollView like Gallery?
  • How to pass onTap Function to ListTile in Flutter?
  • Creating a SearchView that looks like the material…
  • Ukkonen's suffix tree algorithm in plain English
  • Is there a way to treat React components as strings?
  • Playing HTML5 video on fullscreen in android webview
  • Make display data textviews invisible until a city…
  • Converting Hexadecimal String to Decimal Integer
  • How can I get onclick event on webview in android?
  • How to multiply a BigDecimal by an integer in Java
  • Getting wrong position on RecyclerView
  • android.content.res.Resources$NotFoundException:…
  • Error in inserting record due to 787 SQLite exception
  • How to set timer in android?
  • Android ListView headers
  • Why do I get "Exception; must be caught or declared…
  • How using try catch for exception handling is best practice
  • error LNK2005: ✘✘✘ already defined in…
  • IOException: read failed, socket might closed -…
  • Auto-fit TextView for Android
  • Understanding checked vs unchecked exceptions in Java
  • recyclerview opens wrong item after filtering list…
  • How get total sum from input box values using Javascript?
  • Reading a Childs child attribute with Linq
  • EditText, clear focus on touch outside
  • How to convert number to words in java
  • How to get the current location latitude and…
  • What is a NullReferenceException, and how do I fix it?
  • Disable scrolling in webview?
  • Custom Listview Adapter with filter Android
  • How to pass values between Fragments
  • Logging best practices
  • Injection of autowired dependencies failed; nested…
  • Convert array to nested JSON object - Angular Material tree
  • How to hide soft keyboard on android after clicking…
  • java-POST method 415 Error
  • insert tables in dataframe with years from 2000 to…
  • ASP.NET Core Web API exception handling
  • Vuetify stepper alert message when blanks not filled
  • org.hibernate.MappingException: Could not determine…
  • Google in-app billing, a toast breaks everything
  • Use Combine to route SwiftUI Views
  • Error: the entity type requires a primary key
  • Manually raising (throwing) an exception in Python
  • How to set HTML5 required attribute in Javascript?
  • Backbone Collection.fetch gives me Uncaught…
  • Pandas pivot_table: filter on aggregate function
  • Vue - How to make active dynamically based on…
  • Property or method "key" is not defined on the…
  • How can I prevent java.lang.NumberFormatException:…
  • Do you (really) write exception safe code?
  • Node.js Best Practice Exception Handling
  • enable/disable zoom in Android WebView
  • Disable ScrollView Programmatically?
  • org.springframework.beans.factory.BeanCreationExcept…
  • Setting onClickListener for the Drawable right of an…
  • How to add fade animation for this tab
  • Could not load file or assembly 'Newtonsoft.Json' or…
  • Android RecyclerView addition & removal of items
  • Polymer routing: inner routes not reflecting
  • SeekBar and media player in android
  • How can I pass a wct test while rearranging children…
  • How to detect the swipe left or Right in Android?
  • Overwriting txt file in java
  • Why is "except: pass" a bad programming practice?
  • How to receive serial data using android bluetooth
  • Adding gif image in an ImageView in android
  • How to Inject/Replace part of the view and view…
  • how to make column bool data to be true with the…
  • How to download and save an image in Android
  • Nested class: Calling child class properties in parent class
  • Change column type in pandas
  • javascript .replace and .trim not working in vuejs
  • java.lang.NullPointerException: Attempt to invoke…
  • Smart way to truncate long strings

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Get the value of checked checkbox?

Next Post:

Rotating and spacing axis labels in ggplot2

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error