read li-ion battery voltage

ok. This should be a simple task to accomplish, but im having trouble with it.
all im trying to do i read the voltage from a battery on the arduino. when im using the following code

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
    float voltage = sensorValue * (5.0 / 1023.0);
   Serial.println(voltage);

reading the arduino 5v it works fine. open up serial monitor and nice flow of voltage values.
when i try to use the battery it goes nuts.
i did change the

float voltage = sensorValue * (5.0 / 1023.0);

to

float voltage = sensorValue * (4.2 / 1023.0);

but that didnt work.

im assuming it has something to do with reference voltage but need some guidance in the right direction.
or is there another way to do this simply.
ive got a uno and reading a standard 18650 li-ion battery (actually 2x18650 in parallel but the voltage is the same).

when i try to use the battery it goes nuts.

I love technical descriptions of problems.

ok the serial monitor displays random values scrolling down the screen instead of a constant value XD

How is the battery connected to the Arduino? What voltage is the battery, fully charged, as measured using a voltmeter?

I've done similar, but i used the 3v3 out from the arduino and fed this to the aref pin. set aref to external.

Then i feed the voltage in via a potential divider (which loads the battery a little too) with two 600kohm resistors (halve the voltage to make sure Vin < Vcc).

Its a bit quick and dirty, but seems to work ok.

it is connected to the A0 pin with the + and GND with the - of the BATT
fully charged is 4.2V
Normal voltage is 3.7V

what is the right way to do it. the way im doing it MIGHT not be right.

i just thought it would be simple since the arduino is 5v and we are measuring at max 4.2v. (no voltage divider needed) so in my head connect the battery to a ADC (A0) pin and print out voltage value on serial monitor.

nevermind. loose connection on the BATT GND to the arduino GND pin. that was what was causing the bad readings. connect the BATT + to A0 and the BATT - to GND.
open serial monitor and boom. thx